<<

Informatics in Education, 2020, Vol. 19, No. 2, 239–256 239 © 2020 Vilnius University DOI: 10.15388/infedu.2020.12

Arduino and Numerical Mathematics

Đorđe HERCEG1, Dejana HERCEG2 1Department of Mathematics and Informaics, Faculty of , University of Novi Sad Novi Sad, Serbia 2Department of Power, Electronic and Telecommunication Engineering Faculty of Technical , University of Novi Sad Novi Sad, Serbia e-mail:[email protected], [email protected]

Received: November 2019

Abstract. Connecting theory and practice in teaching is sometimes difficult, as it requires expen- sive or delicate equipment, thus limiting the teacher to giving demonstrations in which students are passive participants. Numerical mathematics, as an applied discipline, should be taught on real world examples. By using inexpensive Arduino hardware, we can create simple experiments that are easily reproduced by students. Furthermore, the experiments generate tangible data, which can be processed numerically. The choice of the software used for numerical processing is also an important issue. We present several exercises in numerical mathematics that are based on experiments in electrical engineering with Arduino, and show how to turn them into motivational examples. We also present our experiences in teaching using the developed exercises, as well as some important points and conclusions, which stem from discussions with the participating students and teachers. Keywords: interactive learning environments, numerical mathematics, Arduino, education, teaching.

1. Introduction

Numerical mathematics is studied in some middle schools and in almost all mathe- matics courses at undergraduate level studies. Interpolation is introduced by means of Lagrange polynomial and Newton polynomials. The concept of definite integral is introduced as the Riemann integral, which is defined in terms of Riemann sums and its geometric interpretation. Numerical differentiation is devised from Taylor series and explained geometrically as the slope of the secant. While these topics are important, demonstrations and exercises are often made in class using some arbitrary data, with- out obvious connection to the real world. By using inexpensive Arduino hardware, a teacher can obtain real world data for students to work on, as well as demonstrate the connection between theory and application. We present several examples that were 240 Đ. Herceg, D. Herceg developed with the aim to motivate the students and raise their interest in solving real world problems using the knowledge and techniques learned in class. Our examples are based on Arduino Uno R3, GeoGebra, Mathematica, ++ and C# development envi- ronments. This work is a continuation of our previous work on teaching of Numerical mathematics using (Herceg and Herceg, 2008; Herceg and Herceg, 2009; Herceg and Herceg, 2010). The paper is organized as follows. Section 2 describes motivation and related work. Sections 3, 4 and 5 introduce interpolation, numerical integration and numerical differ- entiation through a brief theoretical introduction and with examples developed with Ar- duino, some programming, GeoGebra and Mathematica. A real world problem is solved for each topic and the connection between theory and practice is established. Section 6 contains an overview of feedback received from the participants in our courses. The results of a pedagogical experiment are in Section 7. Concluding remarks are given in Section 8.

2. Motivation and Related Work

Interpolation, numerical integration and numerical differentiation are topics in the Nu- merical mathematics course, taught at the Faculty of Science, University of Novi Sad. The ‘classical’ approach to teaching consists of oral lectures supported with slides, fol- lowed by practical exercises during which the students solve computational problems on paper, using the software (Mathematica and/or GeoGebra) mainly as a programmable . We sought to improve our teaching materials, classroom activities and exercises by following the ideas and principles explored in the contemporary literature. Having in mind the new demands occurring in educational systems (and) in order to prepare students for future professions where technology offers enormous opportunities for teaching and learning, we chose to rethink our educational paradigm and strategies (Drijvers et al., 2016). In Cheng et al. (2016) it is argued that majority of teaching is based on the ‘teach- ing by telling’ approach which centers on mathematical derivation and ignores the natural connection between theory and application. They propose introducing digital simulation together with hardware-in-loop simulation into teaching practice. To this end, we introduced the Arduino-based exercises described in this paper into class- room activities. Our intention was to better motivate the students and to bring to at- tention the connection between the lessons being taught and their application in the real world. Many authors share the view that in contemporary mathematical model- ing, the process of translating between the real world situations and mathematics in both directions is one of the essential topics in mathematics education, as research and practice enhance each other through the development of new tools for classroom instruction and across a wide range of disciplines (Blum and Niss, 1991; Kaufmann and Schmalstieg, 2002; Zbiek and Conner, 2006; Hohenwarter et al., 2008; Blum and Borromeo Ferri, 2009; Niss, 2012). Arduino and Numerical Mathematics 241

Subject integration is necessary in goal-oriented problem solving. In our case, this pertains to the use of Arduino-based hardware together with mathematical software (Mathematica, GeoGebra) and general-purpose software development environments (Arduino and C# IDEs). A certain knowledge of electrical engineering and physics is also desirable. The role of computers in teaching has been studied for quite some time (Underkoffler; 1969). STEM (science, technology, engineering, and mathematics) edu- cation is focused on developing tools and processes for teaching, which integrate con- cepts that are usually taught as separate subjects in different classes and emphasizes the application of knowledge to real-life situations, enabling teachers to teach mathematics and science much better and more effectively (Burkhardt, 2018; Gonzalez and Kuenzi, 2012; Tomaschko and Hohenwarter, 2017). Providing early exposure to STEM content can ensure that students will continue their interest in STEM subjects through middle and high school up to university level (DeJarnette, 2012; Lavicza et al., 2007; Lavicza et al., 2018; Prensky, 2008). When it comes to the choice of a hardware platform which is suitable for class- room application, one must consider potential obstacles. Many authors are aware that advanced teaching concepts may fail in practice because of high prices and complexity of hardware and/or software or other similar factors which impact low-income societies differently than highly developed ones. For example: Particularly in developing coun- tries, teachers are sometimes willing to learn new teaching tools, but, due to various rea- sons, are not able to implement them in class. Distinctive characteristics of educational systems, culture and financial level also impact the integration of technology in school education (Bhagat and Chang, 2015; Han et al., 2013; Jezdimirović, 2014; Mainali and ( Key,, ), 2012).( , )We,…, chose( , Arduino), = hardware 1,2, … because it is easy to obtain at a modest price, ubiquitous, well supported and easy to configure for the presented teaching topics. 푥� 푦� 푥1 푦1 푥푛 푦푛 푛 ( ) = 푛 푛 . 3. Interpolation �푥 − 푥�� 퐿푛 푥 � 푦� � �=� �=� �푥� − 푥�� ��� 3.1. Definition ( , ), ( , ),…, ( , ), = 1,2, … We start by introducing the Lagrange polynomial. For a given set of data points ( ) = 푛 푛 . 푥( � 푦� ) (푥1 푦1 ) (푥푛 푦푛) 푛 , , , ,…, �푥, −,푥 � � = 1,2, … the Lagrange polynomial is defined as 퐿푛 푥 � 푦� � � � 1 �=�1 �=�푛�푥�푛− 푥�� 푥 푦 푥 푦 ���푥 푦 푛

( ) = 푛 ( ,푛 ), ( , .) ,…, ( , ), = 1,2, … � 푛 � � ��푥 −1 푥 �1 푛 푛 퐿 푥 � 푦푥(�,푦 ),�(푥 ,푦� ),…, (푥 , 푦 ), 푛= 1,2, … �=� �=� �푥 − 푥 � ��� � � 1 1 푛 푛 In the simple case푥 of 푦two points푥 푦 ( =푥 1) 푦we get푛 linear interpolation

푛 ( )( ) ( ) = + = + . 푥 − 푥� 푥 − 푥� 푥 − 푥� 푦� − 푦� 퐿� 푥 푦� 푦� 푦� 푥� − 푥� 푥� − 푥� 푥� − 푥� 242 Đ. Herceg, D. Herceg

Fig. 1. Arduino with a water pressure sensor and a 7-segment display.

3.2. Real World Example

Water pressure in a household water supply is essential to the regular function of water ( , ), ( heaters, ),…, and( ,washing), =machines. 1,2, … To measure water pressure one can use mechanical or ( , ), ( , ),…, ( , ), = 1,2, … 0 0 1electronic1 devices.푛 푛 An electronic water pressure sensor can simply be installed in a water 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), 푛= 1,2, … pipe and connected to Arduino (Fig. 1). The sensor produces output0 0 from1 0.51 to 4.5V,푛 푛 ( , ), ( , ),…, ( ,( ),, ),=( 1,2,, …),…, ( , ), = 1,2, … 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), 푛= 1,2, … 0 0 1corresponding1 푛 푛 to pressures from 0 bar to 12 bar. The dependency is linear. 푥 푦 푥 푦 =푥 1 푦 푛 0 0 To1 measure1 water푛 푛0 pressure,0 1 we1 need to푛 write푛 a C++ program to푥0 read푦0 the푥1 voltage푦1 from푥푛 푦 푛 푛 푥( ,푦 ), (푥( ,푦, ),…,), ((푥, , 푦푥(),…,), ,푦 푛(=), (푥 1,2,, ,푦) …, ) ,…,=( 1,2,푥 , 푦 …) , 푛= 1,2, … = 1 the sensor푛 and convert( it to)( pressure.) The result is displayed on a 7-segment display or ( ) = 0 +0 1 0 1 0 = 1푛 +1푛푥0 푦0 푛 푥1푛 푦1 . 푥푛 푦푛 푛 푛 푥 푦 otherwise푥푥( 푦,푦 relayed), =(푥푥 1, 푦 푦to),…, the푛 (user.푥 , 푦 ), 푛== 1,2, 1 … ( )( ) 푥 − 푥1 푥 − 푥0 푥 − 푥0 푦1 − 푦0 ( ) = + = + . 1 0 1 0 1 0 0 1 0 퐿 푥 푦 0 1 푦 1푥0 푦00 푥푦1 푦1 푥1푛 푦푛 0 푛 푛 푥 − 푥 푥 − 푥 푥 − 푥 푦 − 푦 푥 − 푥 푥 −0 푥 푛 =(푥 1 − 푥 )( ) ( 1 )( 0 ) 1 0 ( ) = + ( ) == + + =. + 퐿 푥 푦 0. 1 푦 1 0 푦 1 0 3.3. Solution 푥 − 푥 푥 −0 푥 푥 − 푥 1 0 푛푥 − 푥1 0 푥1 − 푥00 푥 − 푥0 푦1 − 푦0 1 0 푥 − 푥 1 푉푥1 − 푥 00 푥 − 푥 1 푦( − 푦 )( 0 ) ( ) = 퐿 푥 + 푦 0 1= 푦+ 1 0 푦 . 1 0 퐿 푥 푦 0 1 푦 1 0 푦 푥 − 푥 1 푥 0− 푥 푥 − 푥 푉 푥 − 푥 푥 −01 푥 0 푥 − 푥 0 0 1 0 First, a 푥formula − 푥 to convert푥 − 푥 the voltage푥 − 푥from푦 the− 푦sensor’s output pin to pressure must 1 =0 1023푢 /5 1 0 퐿 푥be constructed.푦 0 1 Arduino푦 1 has0 analog푦 input1 pins0 which can measure voltages from 0 to 푥 − 푥 푉 푥 −0 푥 푉 푥 − 푥 = 1023푢 /5 50 and represent them as unsigned 10-bit integers, from 0 to 1023. Knowing the sen- 푎 = 0.5푢 푉 sor output’s range, integer푉 values which푢 correspond to input values of 0.50푎 and 4.50푢 = 1023푢 /5 = 1023 /5 = 0.5 푉 1 (0,0) (5,1023) are determined.푢 = 4.5 Interpolating polynomial is constructed for points , , 푉 1 푉 which 푎yields a ratio푢 = 1023between푢 /5 the푎 input= 0.5 푢voltage on the sensor and analog푢 reading= 4.5 2 = 0.5 = 1023푢 = 102/5. 1 푎 푢 푢1 푢 푢2 By substituting푢 = 4.5 = 0.50.5 and = 4.54.5 and rounding the results, we get = 102 푎 1 푢 and 푎 = 921 . These are the readings Arduino will get when sensor voltages are 0.50 2 푢1 푢2 푎1 and 4.50 푢respectively.= 102 =The 4.5 readings =are102 converted to pressure by constructing another= 921 푎2 푉 interpolating polynomial2 for points1 (102,0), (921,12): 2 1 푢 푎 푎 푉푎 = 921 = 102 = 921

2 1 2 푎 4( 102푎 )= 921 푎 ( ) = . 273 2 푎 − 푎 푟 푎 ( , ), ( , ),…, ( , ), = 1,2, …

0 0 1 1 푛 푛 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), 푛= 1,2,( …, ), ( , ),…, ( , ), = 1,2, … 0 0 1 1 ( ,푛 )푛, ( , ),…, ( , ), = 1,2, … 0 0 1 1 푛 푛 푥 푦 푥 푦 =푥 1 푦 푛 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), 푛= 1,2, … 0 0 1 1 푛 푛 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), 푛= 1,2, … 0 0 1 1 푛 푛 푛 ( 푥)( 푦 푥 )푦 =푥 1 푦 푛 ( ) = + 0 =0 +1 1 푛 푛 . 푥 푦 푥 푦 푥 푦 푛 1 0 0 = 11 0 1 0 푥 − 푥 1 푥 − 푥 0 푥 − 푥 푦 − 푦 푛 ( )( ) 퐿 푥 푦 0 1 푦 1 0 푦 1 0 푥 − 푥 푥 −0 푥 ( ) = 푥푛 − 푥 + ( )(= + ) . ( ) = + 푥 −= 푥1 + 푥 − 푥0 .푥 − 푥0 푦1 − 푦0 11 0 0 1 0 1 0 0 푥 − 푥퐿 푥 푥푦 − 푥0 1 푦 푥1 − 푥 0 푦 푦− 푦 1 0 1 푉0 1 푥 − 푥 0 푥 −0 푥 푥 − 푥 퐿 푥 푦 0 1 푦 1 0 푦 1 0 푥 − 푥 푥 −0 푥 푥 − 푥 푢 = 1023 /5 푉 푉 푎 푢 = 0.5 = 1023푢 /5 = 1023푢 /5 푢1 = 4.5 푎 = 0.5푢 푎 = 0.5푢 푢2 1 = 102 푢 = 4.5 푢1 1 = 4.5 Arduino and푎 = Numerical921 Mathematics 푢2 243 2 = 102 푢 = 102 2 1 푎 4( 102) 푎 = 921 The resulting polynomial ( ) =converts readings. from1 the analog input pin on the 273 푎 = 921 2 Arduino to pressure in the range from 0푎 bar − to 12 bar. The calculation푎 can4( be executed102) 푟 푎 2 in Mathematica (Fig. 2). 푎 4( 102() ) = . ( ) = . 273 The result can be obtained geometrically in GeoGebra,273 by constructing푎 − a line through points A1 = (102,0) and A2 = (921,12). The conversion푎 − is푟 obtained푎 by placing 푟 푎 the point C on the line. By positioning the point C at the coordinate equal to a value read from the sensor, the corresponding pressure can be read from the 푥 coordinate (Fig. 3). The axes are scaled non-proportionally in this exercise.푥 It should be noted that a built-in Map function exists in Arduino, which푦 is intended 푦 for the same purpose. However, the function is implemented using integer arithmetic and, due to truncation errors, sometimes yields unsatisfactory conversions.

Fig. 2. Interpolation in Mathematica to convert sensor readings to pressure.

Fig. 3. Conversion of sensor readings to pressure in GeoGebra. ( , ), ( , ),…, ( , ), = 1,2, … ( , ), ( , ),…, ( , ), = 1,2, … ( , ), ( , ),…, ( , ), = 1,2, … ( , ), ( , ),…, ( , ), = 1,2, … 0 0 1 1 푛 푛 0 0 1 1( ( , , ),푛(), (푛, ,푥(),…,),푦,…,(),((푥, ,,푦), ) ,…,, =(= 1,2,푥 1,2,, 푦 …) …, 푛= 1,2, … 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), 푛= 1,2, … 0 0 1 1 푛 푛 0 0 1 1 푛 푛 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), 푛= 1,2, … 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), 푛= 1,2, … 0 0 0 0 1 11 10 0 푛 푛1푛 푛1 푛 푛 0 0 1 1 푥( 푥(,푦 ,푦)푛, ()푥,푛(푥,푦,푦)푥,…,),…,푦(푥(푥,푥푦, )푦, ) , 푛 =푛== 1,2,푥 1 1,2, …푦 … 푛 푥 푦 푥 푦 =푥 1 푦 푛 0 0 1 1 푛 푛 0 0 1 1 푛 푛 푥 푦 푥 푦 =푥 1 푦 푛 푥 푦 푥 푦 =푥 1 푦 푛 0 00 0 1 11 1 푛 푛푛 푛 ( , ), ( , ),…, ( , ), = 1,2, … 푥 푥푦 푦 푥 푥푦 푦 =푥= 1 푥 1푦 푦 푛푛푛 ( )( ) 푛 ( ) = ( )(+ ) = + . ( ) = + = + . 0 0 푛1 1 푛( 푛 )( ) 푛 ( )( ) 1 ( ) = 0 푥( +,푦 ), (푥 ,푦0 )=,…,1 (푥+0, 푦 ), 푛=( 1,2,) = … . + = + . 1 01 0 푥푛 −푛 푥0 1 1 푥(0 −( 푥 )()(0 푥) −) 푥 푦 − 푦 푥 − 푥 푥 − 푥 푥 − 푥 푦 − 푦 1 0 0 1 0 1 0 0 1 0 1 0 ( () =)1= 퐿 푥 +0+푦 0 1= =푦 +1+ 0 푦0 0 .1 . 11 0 푛 푛 퐿 푥 푦 0 1 푦 1 0 푦 푥 − 푥11 0 푥 0−푥 푥 − 푥 1 푥 −푥 − 푥 0 푥 − 푥 1 푦 − 푦 0 푥 − 푥 1 푥 − 푥 0 푥 − 푥 푦 − 푦 1 0 0 0 푥 1푦 0푥 푦 =푥 1 푦 푛 푥 − 푥 푥 −푥0 − 푥 푥 1 푥 − 푥푥퐿 0−푥 푥 푦 푥 −0 푥 10푦 푦−1 푦1 0 0 푦 1퐿 푥 0 푦 0 1 푦 1 0 푦 1 0 1 1 (0 0, 푥 −), ( 푥 , 1 )1,…,푥 −( 푥 , 0)0, 푥=푥− 1,2, 푥 … 푦 −푥 푦−0 푥 푥 − 푥 푥 − 푥 푥 −0 푥 푥 − 푥 퐿 퐿푥 푥 푦 푦 0 0 1 1 푦 푦 1 1 0 0 푦 푦 1 1 0 0 푥 푥−− 푥 푥 푥 푥−0− 푥0 푥 푉 푥 푥−− 푥 푥 푛 ( )( ) 0 푉 0 1 1 푛 푛 ( , ), ( , ),…, ( 푥(, ,푦), ), (푥=, 1,2,푦 ),…, … (푥 , 푦 ), (푛=) 1,2,= … + 푉 = + . 푉 ( , ), ( , ),…, ( , ), = 1,2, … 1 0 0 1 0 ( , ), ( , ),…, ( ,푉 푉 ), ==1 1,2,1023푢 … /50 푥 − 푥 1 푥 − 푥 0 푥 − 푥 푦 − 푦 0 0 1 1 =푛 10230푛푢 0 /5 1 1 푛 푛 퐿 푥 푦 푦 푦 푥( ,푦 ), (0푥 ,0푦 ),…,1 (1푥 , 푥푦 )푦, 푛푛=푥푛 1,2,푦 … =푥 1 푦 푛 0 =1 1023푢 1/5 0 1 0 = 1023푢 /5 푥( ,푦 ), (푥 ,푦0 )0,…, (푥1 , 1푦 ), 푛=푛 1,2,푛 … 푥 − 푥 푥 −0 푥 푥 − 푥 푥( ,푦 ), (푥 ,푦 ),…,=(푥=1023푢,1023푦푢), /5 푛/5 푎= 1,2,= … 0.5 푢 0 0 1 1 푎 푛 푛= 0.5푢 푥 푦 푥0 푦0 1 =푥1 1 푦 푛 푛 푛 ( )( 푎 )= 0.5푢 푉 푎 = 0.5푢 푥 푦 (푥 ) 푦=0 0 =푥1 푦1 + 푛 푛 푛 = +1 . 푥 푦1 푥 푦 푎 푎=푥 1= 푦= 0.5푢 0.5 푢푛 푢 = 4.5 푢 = 4.5 1 0 0 1 10 1 1 푛 0 푥 − 푥( 1 )(푥 − 푥 ) 0 푥 − 푥 푦 −푢 푦 = 4.5 푢 푢 = 4.5 ( ) = + 퐿 푥 푦=푛 0 + 1 푦 (11 1 0)( .푦 2 ) 1 0 = 1023 /5 ( ) = + 2 푥 −= 푥 푛+푢푥푢=−0= 4.5푥 4.5 ( 푢 =. )(102푥 − 푥 ) 1 ( ) = 0 푢 = 102+ 0 =1 0+ . 2 2 1 0 푥 − 푥 1 1푥 − 푥 0 0 푥 − 푥 푦 −0 푦 1 0 푢 = 102 푢 푥 − 푥 푥 −1 푥 푥0 − 푥 푦 − 푦 0 1 0 푎 = 0.5푢 = 102 퐿 푥 1푦 0 01 푦 1 푥10 − 푥푦 푥0 −1 푥2 2 0 푥 −1 푥 푦 − 푦 퐿 푥푥 −푦 푥 10 푥1 −00푦 푥 11 0 1푦 푥푢−푢= 푥=102푉 11020 0 푎 = 921 퐿푥 푥− 푥 푦 0푎푥 =−01921 푥 푦 1 0 푥푦 − 푥 1 0 1 1 푥 − 푥 푥 −0 푥 푥 − 푥 푎 = 9211 푎 = 921 1 1 2 푢 = 4.5 푉 2 푎 푎=푢=921921 푎 4( 102) 푎 ( ) = 1023 /5 2 2 4 푉 102 ( ) = . 2 ( ) = . 푉 273 푎 4( 푢102) 푎 4( 102) 2 2 ( ) = = 102. ( ) = . 푢 273 푎푎 푎4(4( 푢102102) ) 푎 − = 1023 /5푎 − = 0.5푟 푎 273 273 = 1023푢 /5( () =) = . . 푎 − 1 푎 − 푟 푎 = 1023푢 /5273 273 푎 1 푟 푎 = 921 푟 푎 푎 = 0.5푢 푢 =푎 −푎4.5 − 푎 = 0.5푢 푟 푟푎 푎 2 푎 = 0.5푢 푥 푎 ( ) 1 푥 2 4 102 푢 = 4.51 푢 = 102 (푥 ) = . 푥 1 273 푢 = 4.5 푥 푥 푦 푦 푢 = 4.5 푎 − 2 1 ( ) 푟 푦푎 푢 = 1022 푎 = 921 = 푛 푦 = 푢푛 ( ) 2 = 102 푢 푦 푦 ∗ = 푛 ( ) = 푛 ( ) 244 ∗ = 102 Đ. Herceg, D. Herceg푖 1 2 푖 푖 푖 = 푛 푛 ( ()퐴) � 푓 푥 ∆푥 ∗ ∗ 푎 퐴= 921�1 푓 푥 ∆푥 =푎 4( 102)푖=1 푥푖 푎 1 푖 푖 푖 푖=1= 921 푎( ) = =∗ ∗ . , [퐴 ,�].푓 푥 ∆푥 퐴 � 푓 푥 ∆푥 =4. Numerical, Integration[ = ,921]. 273� 푖 � 푖 푖=1 푖=1 2 퐴 퐴 �� 푓 푓푥 푥∆푥∆푥 ∗ = , [ , ]. = , [ , ]. 푎 4( 2102) ∗ �=1푖=1푖푎 − 푖 푖−1 푖 푖−1 푖 푦 ( 푖) = 푖 푎푖−14( .푖 =102=푟 2푎)푖−1 ∆푥푖, , 푥 −[ [ 푥 ,=,].푥 ]. ,∈ 푥 푥 ∗ ∗ ∆푥 푥(−)273 푥== 푥 ,∈ 푎푥4. ( 푥 102 ) 푖 푖 푖−1 = 푖 푛 (푖−1) 푖 푖 푖 푖−1 푖 푖−1 푖 4.1. Definition푎 − 273( ) = ∗ ∗. ∗ ∆푥 푥 − 푥 = 푥 ,∈ 푥 푥 ∆푥 푥 − 푥 = 푥 ,∈ 푥 푥 ∗ 푎� −푖 � 푖 �−1273푖−1 � 푖 �−1푖 푖−1� 푖−1푖 ∗ 푟 푎 푖 ∆푥∆푥푖−1 푥 푥−− 푥푎 푥= −=푥 푥,∈ ,∈ 푥푥푥 푥=푥푥 ∗ � � ∗ 푟 푎 푥 =푥 푥 푖 퐴 푖−1� 푓 푥 ∆푥 푖 푖−1 푟 푎 ∗ ∗ ∗ 푥 =푥 �=1 푥 =푥 The concept∗ of definite� integral푖 �−1푖−1 is introduced푖 푖 as the= problem of, area under[ ,a graph.]. The 푖 푖 푥 푥 =푥=푥 푥 +푥 ∗ ∗ Riemann푥 푥 sum+푥 is defined as푦 = . 푖 푖 ∗ 푖 푖 푥 ∗ � 푥 � +푥 �−1 � �−1 � 푥 +푥 = . =푥 푛 ∗ ( ) 2 ∆푥 푥 − 푥 푥 ∈ 푥 푥 2 � 푖 � 푖 ∗ 푖 푖−1 = =. , = . ∗ 푖 푖−1 푥 푥 +푥+푥 푖 푥 푥 2 2 푦푖 푥 푥 = = ∗ 푥. . ∗ 푖 ∗푖−1 ∗ 푖 푖−1 푥 푦 � =� ( + )/2. 푖 푥 푥� �−1 푖 푥 푥 푛 ( ) 퐴 푦� 푓2푥2 ∆푥 푥 푥 = = ( + )/2.∗ ∗ �=1� 푖 �−1푖−1 푥 = 푥 = 푛 ( ) � 푖 푥 푥 푥 푥∗ = ( + )/2. = ( + )/2. ∗ ∗ == 푥푛 푥 ( ,) 푖 [ 푖 , ].푖−1 ∗ 푖 � 푖 � 푖−1∗ = = ( ( + + 푥)/2.)/2. 푥 푥 ∗ � � ∗ 퐴 =�푥 푓 푥.푥 ∆푥 푥 � � ∗ ∗ 푖 푖 푖−1푥 +푥 푖 푖 푖−1 = . �=1푥푖+푥퐴 푖−1 � 푓 푥� ∆푥∗� �−1� �� �−1 � 푥 푥 푥 푥 푥 푥 = ∗ , �=1 ∆푥[ 퐴=, 푥�].∗− 푓 푥. 푥 = ∆푥푥 ,∈ 푥 푥 == . . ∗ 푥푖+푥푖−1 푖 � �=1푖 � 푖 �−1푖−1 2 2 푥푥푖+푥푖−1푥 푥 ∗ � 푖 푖−1�−1 푖 = = . .푥 ∗ = ∗ 푥 , ∗ 푥 [푥 , ]. ∗ 푥 푥 +푥푥 푥 2 where 푖 = Several special cases� 푖 are observed, left rule for 푥�+푥푖�−1� 푖−1 � �−1 � = �−1 � 2 � �−1 푥 2 ∗ ∗ ∆푥푥 +푥 푥 − 푥 = 푥 ,∈ 푥 푥 푥 ∗=푥 푥 � � right� rule�−1 for and�−1 midpoint� rule, for = = ( + )/2. In the case of = 푥 푥푖 2 2 ∆푥 푥 − 푥 푥� ∈ 푥 푥 푖 equidistant∗ points,푖 i.e. =∗ = for =ℎ 1,2,∆푥 … , , the formula∗ becomes � �−1=ℎ 1,2,∆푥 … , � � � 푖 � �−1 푖 푥 푥 =푥 푥 . =ℎ 1,2,푥 ∆푥 … ,푥 푥 =ℎ 1,2,∆푥 … , � 푖 ℎ ℎ푥�+푥∆푥�−1∆푥 푖 푛 푖 푛 ∗ = 1,2, … , 푥� 2 푖 푛 푖 푛 = 푛 ( ). 푖 푛 = 푛 ( ). = 푛 ( ). ∗ 푖 = 푛 ( ). ∗ ∗ 퐴 ℎ � 푓 푥 푖 푖 푖=1 ∗ 퐴 ℎ � 푓 푥 퐴 ℎ � 푓 푥 푖=1 푖=1 If the function f is퐴 unknownℎ � 푓 푥and푖 only the points ( , () are, )available, ( ) can be 푖=1 ( , ) ( ) ( + )/2 ∗ substituted with and thus the trapezoidal rule푖 is푖 obtained.푖 푖 Depending푖 on the course∗ level, Newton-Cotes quadrature formulas may 푥also푦 be푥 used푦 . 푓 푥 푥푖 푦푖 푓 푥푖 푦푖 푦푖−1

4.2. Real World Example

This example presents the working principle of a digital electrical energy meter, similar to those found in households. The example electric circuit consists of a power supply unit and two loads B1 and B2, which can be independently switched on and off (Fig. 4). The voltage and current are measured by the Arduino, and then the consumed energy is calculated by numerical integration.

Fig. 4. Schematic for the current measuring experiment ( , ), ( , ),…,( (, ,), ()(, , , =),…,) 1,2,, ( ( …, , ),…,), ( =, 1,2,), … = 1,2, …

0 0 1 1 0 푛0 푛 1 0 1 0 1 푛 1 푛 푛 푛 푥( ,푦 ), (푥 ,푦 ),…,푥( (푥,푦 , )푦, ()푥, 푥( ,푦푛,=푦),…, 1,2,), (푥( …푥 ,푦, 푦),…,), 푛(푥=, 1,2,푦 ), … 푛= 1,2, … 0 0 1 1 푥0 푦푛0 푛 푥1푥푦01푦0 푥푥1푛푦푦1푛 푛 푥푛 푦푛 푛 푥 푦 푥 푦 =푥 1 푦 푛 = 1 = 1 (( ,, )),,(( ,, )),…,,…,(( ,, )), , == 1,2, 1,2, … … 푛 ( 푛 )( 푛 )( )( ( ))( ) ( ) = ( ) = + + = + = + . . ( ) = 00 00 +11 11 푛푛= 푛푛 + . 푥(푥( ,푦,푦 )),1,(푥(푥 ,푦,푦 )),…,,…,(푥(0푥푥 −,,푦 푥푦1)), , 푛푛푥== −푥 1,2, 1,2, 푥−10 푥 …0 … 1 푥 −0 푥0푥 − 푥0 푦1푥− − 푦 푥00 푦1 − 푦0 1 0 푥 − 푥 1 1 푥 −0 푥1 0 0 1푥 − 푥 푦 1 −0 푦 0 퐿 푥 푦 퐿 푥푦 푦 퐿 0푥 푦1 푦 푦0 1 1 0 푦 푦1 0 푦1 0 1 0 000 00 1 11 11 1 푥0푛−푛 푥푛푛 푥 푥− 푥−01 푥 0푥 −0 푥 푥 − 푥 푥 − 푥 ( (, ,), (), (, ,),…,푥)푥푥,…,(푦푦−( 푥, 푥푥,), 푦 푦 ),푥 = −0 1,2,== 푥푥 푥 11,2, 1 … 푦푦 … 푛푛 푥 − 푥 ( , ), ( , ),…, ( , ), = 1,2, …( (, ,), (), (, ,),…,),…,( (, ,), ), = 1,2,= 1,2, … … 0 00 0 1 11 1 푛 푛푛 푛 푉 푉 푥( 푥(,푦 ,푦), (푥), (,푥푦 ,)푦,…,),…,(푥 (,푥푦 ,)푦, )푛, = 푛푛 1,2,=푉 1,2, … … (( )()( )) 0 0 1 1 푛 ((푛 )) 0 00 0 1 11 1 푛 푛푛 푛 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), = =푛= 1,2, … 푥( ++푥(,푦 ,푦), (푥), (,푥푦 =,)=푦,…,),…,(++푥 (,푥푦 ,)푦, )푛, = 푛 1,2,= 1,2, … . . … 푥0 푥푦00 푦0푥1 푥푦11 푦1 푥푛 푥1푦1푛푛 푦푛 푛 푛 00 = 1023푢00 1/51= 102300푢 /5 11 00 푥=푥 − − 1= 푥 푥 1 11=푥푥 −1023 −푢 푥 푥 /5 00 푥푥 − − 푥 푥 푦푦 −− 푦 푦 ( , ), ( , ),…, ( , )0, 0 = 1,2,1 …1 푛퐿퐿 푛푥푥 푦푦 0 푦푦00 0 1 1 1푦푦 푛 푛 푛 푥 푦 푥 푦 =푥 1 푦 푛 푥푥00−− 푥 푥11푥 푥푦 푥푥푦11−푥− 푥 푥푥푦00 푦 =푥 1= 푥푦 1 푦푥푥11푛−− 푥푛 푥00 00 푎 푢푎 푢 0 0 1 1 푛 푛 푛 푛 푎 ( (= 0.5)(푢 )( ) ) = 0.5 = 0.5 푥 푦 푥 푦 푥 푦 푛 ( ) ( , ), ( , ),…, ( , ), = 1,2,( …=) =푛 + + = = + + 푛 . . ( , ), ( , ),…, ( , ), = 1,2, … ( )( ) 푉푉 푛 1 ( ( 1 )( )( ) ) ( ) = + =1 1 + ( )(0=)0= 1. + 0 + 0 1 1 0 =푢0 = + + 푢 . . ( , ), ( , ),…,0 (0 , 1), 1 = 1,2,푛 … 푛 1 1 0 푥0 −푥 푥 − 푥 1 푥1 −푥 푥 − 푥 0 0 푢푥 −=푥 푥 − 4.5 푥 푦 −푦 푦− 푦 = 4.5 = 4.5 푥 푦 푥 푦 푥 푦 푛 퐿 1 퐿푥 푥 푦 푦 0 푦 푦 0 푦1 푦 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 푛 푛 = 1 푥 − 푥 푥 −푥0 푥−푥0 푥−1 푥1 푥푥1 −푥1 푥−0 푥0푦 −푥 − 푦푥 푥 − 푥푥1 −푥1푥 푥− −0푥 푥 푥 −0 푥 푥 −푥 푥 − 푥푦 −푦 푦− 푦 0(푥 0, 푦 ),1(푥1, 푦 ),…,푛(푥푛, 푦 ), 1푛 = 1,2,0 … 1 0 1 01 0 0 0 ==10231023푢푢 1 /5/51 20 0 2 (푥 푦 ) (푥 푦 ) (푥 푦 ) 푛퐿 푥 푦 0 1 푦 1 0 푦 퐿 퐿푥 1푥 푦 0푦0 0 21 1푦 푦1 1 0 0푢푦=푦102 푢 1= 1021 0 0 , , , ,…, , , = 1,2, … 푥 − 푥 푥 −0 푥 푥 − 푥푥 −푥푢 푥−= 푥102푥 −푥0 푥− 0 푥 푥 −푥 푥− 푥 0 0 1 1 푛 푛 푛 ( )( ) 푥 푦( ) 푥 푦 푥 푦 푛 푉 푉 0 0 1= 1 푛= 1+푛 = + . 푎푎 1 == 0.5 0.5푢푢 1 1 푥 푦 푥 푦 =푥 11 푦 푛 0 0 1 0 푎 푎 = 921 푎 = 921 푥 − 푥 푥 − 푥 푥 − 푥 푦 − 푦푉 = 921 푉 푉 1 0 1 0 11 퐿 푥 푦 0 푛 1 푦 1 ( 0 푦)( ) 1 0 = 1023=푢1023푢 /5 /5 푢푢 == 4.5 4.5 2 2 ( ) = + 푥푛 − 푥 = 푥 +−0 푥 푥. − 푥 2 푎 4( 102푎 4)( 102) ( )( ) = 1023푢 /5 푎 4( =1021023=푢)1023푢 /5 /5 ( ) = +1 =0 + 0 1 . 0 ( ) = ( ) = . . 푥 − 푥 푥 − 푥 푥 − 푥 푦 − 푦 푎 푎 푢 푢( ) =22 . 273 273 1 0 1 1 0 0 = 0.5=0 0.5 1 0 = 4.5= 4.5 푢푢 ==102102273 퐿 푥 푦푥 −0 푥 1 푦푥 −1 푥 0 푦 푥 −푉 푥 1푦 − 푦0 푎 − 푎 − 1 0 1 = 0.5 0 = 4.5 푎 = 0.5푢 = 4.5 푎푎 − 푎 푢 푢 퐿 푥 푦 0 푥 −1 푥 푦 1 푥 −0 푥 푦 1 1 1 푥 −0 푥 2 2 =0.5 =푟 4.5 푎 푟 푎 푟 푎 푥 − 푥 푥 − 푥 푢 푢 푥 − 푥 푢 푢 11 0 = 102= 102 = 921= 921 푎푎 == 921921 1 = 1023푢 2 /5 1 1 2 2 푢 = 102푉 푢 = 921 푢 =푢 102= 102 푢 푢= 921= 921 1 1 2 2 22 푥 푥 푉 푎 푎 푎 푎 4( 4( 102102) )푎푎 44푥(( 102102)) 1 푎 2푢 = 0.5 = 4.5푎 푎 1 1 ( )(=) = 2 2 (( .) )==. . . = 1023푢 /5 푎 4푎( 102) 푎 273푎 273 273273 4( 4( 102102) ) 푢 ( ) = . 푎 −푎 − 푦( )(=) = 푦. . 푦 1 2 = 1023 /5 273 푎푎 − − 273273 푢 = 102 푢 = 921 푟 푎푟 푎 푟푟 푎푎 = 푛 ( =) 푛 ( ) 푎 푢 푎 − = 푛 ( ) 푎 −푎 − = 0.5 = 4.5 푟 푎 푟 푎 푟 푎 ∗ ∗ = 0.5 = 4.5 푎 푢 ∗ 푖 푖 푖 푖 푎1 푎2 ( ) 푖 푖 퐴 � 푓 퐴푥 ∆푥� 푓 푥 ∆푥 1 2 푥4 102푦 퐴 � 푓 푥 ∆푥 푖=1 푖=1 푢 푢 ( ) = 푥 .푦 푖=1 푥푥 1 = 102 2 = 921 =[ ] =, [ , , ]. [ , ]. 푢 = 102 푢 = 921 푥 푦 273 푥 푥 푦 푦= =푛 푛( =() ) , , . 푎 − ∗ ∗ 1 2 ∗ ∗ ∗ 푎 푎 푟 푎 = 푛 ( ) 푖 푖 푖−1 푦푦 =푖 푖 =푛 푛푖−1푖( ()푖푖−1푖 ) 푖 푖 푖−1푖−1 푖푖 푖−1 푖 1 2 4( 102) ∆푥 푖 푖푥 푖 −푖 푥 ∆푥푥 ∈ 푥 −∆푥푥 = 푥푥−,∈ 푥 푥= 푥푥 ,∈ 푥 푥 푎 푎 ( ) = . ∗ 퐴 퐴�� 푓 푥 푓 푥∆푥∆푥 = , ∗ ∗ 4( 102) 푖=1푖=1 == 푛푛 (( )) ( ) 273 푖 푖 푖 ∗푖 푖 푖 ∗ = . 퐴 � 푓 푥 =∆푥= , , [ [ ,∗ ], .퐴 ]. � 푓 푥 푖−1 푖−1 273푎 − 푖 푖−1퐴∗∗ � 푓 푥푖∆푥 ∆푥 푖 푥 푦 푖=1 푖 푖=1 푖=1푖푖 푥 =푥 푥 =푥 푟 푎 푎 − = , [ , ]. ∗ ∗ 퐴퐴 푥�=�== 푓 푓푥 푥푥푖 ∆푥∆푥, , [ [ , ],. ]. 푖 푖 푖 푖 푖−1푖−1 푖 푖 푖−1푖−1푖 푖 푟 푎 = 푛 ( ) ∆푥∆푥 푥 −푥 푥− 푥 푥 푥∈ ∈푥 푥 푖=1푖=1푥∗ 푥 ∗ ∗ ∗ = = =,= , , , [[ ∗,, ]∗푖]. . 푖 푖 푖 ∗ 푖 푖 푖−1 푖 푖−1 푖 푖 푥푖 푖 푖+푥푖푖 푖−1 푖−1 푖 푥푖 푖−1+푥 푖−1푖 푥푖 +푥 푖 푖 ∆푥 푥 − 푥 = 푥 ,∈ 푥 ∗푥 ∗ ∆푥 ∆푥 푥 −푥∗ 푥∗−= 푥 =푥 =,∈푥 ,푥∈ 푥 푥 =.푥 . 푥 푦 퐴 � 푓 푥 ∆푥 푖 푖 푖−1푖푖 푖−1 푖푖 =푖−1푖−1 푖푖 . 푖−1푖−1 푖푖 푥 푦 푖=1 ∗ 푥 푥=푥 =푥 2 ∗ ∗ 푖 2 푖−1 푖 2 푖−1 = 푛 ( ) ∆푥∆푥 푥 푥 −−∗ 푥 푥 ==푖 푥푥푖−1,∈ ,∈ 푥푥 ∗ 푥푥 ∗ = , [ , ]. 푖 푖−1 푥 푥 푖 푖 푖−1푖 푖−1푥 푥푖 푥 푥 = 푛 ( ) 푥 =푥 ∗ ∗ 푖 ∗∗ 푥 푥=푥푥=푥 푥 ∗ 푖 푖 푖 푖 푥 푖 푖 ∗ 푥 푥+푥 +푥 = (푖푖 + 푖−1푖−1 )/2. = ( + =)/2. ( + )/2. 퐴 �푖 푓∗ 푥푖 ∆푥푖−1 푖 푖−1 푖 ∗ 푥푥 ==푥푥 ∗ ∗ ∆푥푖=1 푖 푥 −푖 푥 = 푥 ,∈ 푥 푥 푖 푖 = = . . 푖 푖∗ 푖 푖 ∗ 퐴 � 푓 푥 ∆푥 푥 +푥 2 2 ∗ 푥 푥+푖 푥 +푥 푖 푖푖−1 푖 푖−1 = 푖=1 , [ , ]. ∗ ∗ 푖 푖 푖−1푖−1푖 ∗푖∗ 푖−1 푥 푥 푥푥 푥 푥 ∗ = . = 푥 .푥 =푥 푥푥 . 푥푖푖 푥 푖푖= = . . = , ∗[ 푖 , ]. 푖−1 = . 2 푖 푖 푥푥 ++푥푥 2 2 푥 푥 ∗ 푖 푖−1 푥 푥푖푥+푥푖−1 푥푖+푥푖−1 ∗ ∗ 푖 푖 푖−1 푖−1 푖 푖 푖−1 ∗ 푖 푖−1= 푖 ∗ 푥푖+푥푖−1푥 푥 ∗ = (= (+∗ + )/2.)/2.== 푥. . 푥 푥 푥 ∆푥 푥 − 푥 = 푥 ,∈ 푥 푥 푖 푖 푖 푖 푖 푖 푖 푖−1 푖 푖−1 ∗ 푖 푖 푥 푥 2 푥 2 푖푖 푥22 푖−1푥푖−1 ∆푥 푥 − 푥 = 푥 ,∈ 푥 푥 푥 =2 ( + )/2.∗ ∗ ∗∗ 푥푥 =푥푥 (= (+ + )/2.=)/2. = ∗ 푖 푖 푖 푖 푖 푖 푖−1푖−1 푖푖 = 푖 푖−1 푥 +푥 푥 푥 푥 푥 푥 푥 푥푥 ∗ 푥 =푥 = = = . . . ∗ == ( ( ++∗ ∗ )/2.)/2. 푖 푖−1 푖 푖 푖−1 푖 푖푖 푖 푖 푖−1 푖−1 푖 푖 푥 =푥 ∗ 푖 ∗2푥푖+푥푖−1푥푖−1푖+푥푖−1 푥 푥 푥 푥 푥 푥 푥 푥 푥ℎ ∆푥 ℎ ∆푥 = ∗ . ∗ 푥 푥 = = . . ∗∗ =ℎ 1,2,∆푥 … , = 1,2, … , = 1,2, … , 푖 푖 푖 푖 푖 2 2 푖푖 푖푖 푖−1푖−1 ∗∗ 푥 푥푖+푥+푖−1푥 푥 푥 푥 ∗ ∗푥푖+푥푥푖−1푖+푥푖−1 푥푥 푥푥 푥푥 푖 푖 = ( + )/2. == . . = = 푥푖 =+푥 2 . 푖 푖 2 2 푖 푖푛 푛 푥 ∗∗ 푥푥푖+푥푖+푥푥푖−1푖−1푥 푖 푛 = 푖 2 ∗.푖−1 = = = ∗ 푖푖 푖 푖 = 푛 (=). 푛 ( ). 푖 푥2 푥푖 푖 푖−1 푥푥 22 ℎ ℎ∆푥∆푥 = 푛 ( ). = . ∗ 푥 푥푖 푥푖−1푥 푥 푥 = 1,2,= 1,2, … , … , == 푖 푖 ∗ 푖 푖 ∗ ∗ 푥푖+푥푖−1 푥 = ( + )/2. =ℎ 1,2,∆푥 … , =ℎ 1,2,=ℎ∆푥 1,2, …∆푥 , … , 푖 푖 ∗ = ( + )/2. Arduino and Numerical Mathematics 245 푖 퐴 ℎ � 푓퐴 푥 ℎ � 푓 푥 푖 ∗ 푖 푖 푛 푛퐴 ℎ � 푓푖푖푥 푖=1 푖=1 푥 2 푖 푖−1 ==ℎℎ 1,2, 1,2,푖=1∆푥∆푥 … … , , ∗ 푥푖 푥 푥 = ( , ) (( ,) ) ( , ( ) + ( ) ) /2 ( )( + )(/2 + )/2 = . 푖 푖 푖−1 푖 푛 = = 푛 푛 ( (). ). 푖 푖 푛 푛 푥Assuming푥 푥a constant voltage on the power supply, calculate the energy consumed∗ by∗ = 푥푖+푥. 푖−1 ∗ ∗ ∗ ∗ 푖 푖 푖 = 푛 ( )푖푖. 푖 푖 푖 푖 푖푖푖−1푖 =푖 푛푛=푖 푛 푛(푖−1(). 푖). 푖−1 푖 푥푖+푥푖−1 the loads over an intervalℎ of∆푥 time, defined푥 푦 by start time푓 푥 and 푦 end 푥time 푦 푦 푖푓 .푥 푖푦During푓 that푥 푦 푦 푦 푦 ∗ 푥 2 = 1,2, … , ∗ 퐴 퐴ℎ �ℎ � 푓 푥 푓 푥 ∗ ∗ 푖 = 푖=1푖=1 == 푛푛 (( )). . 푥 2 interval the loads are randomly( (, ,) switched) (on퐴 ()and) ℎoff. � 푓(푥푖(+ + )/2)/2 푖 푖 = 1 2 1 2 1 2 퐴 퐴ℎ∗∗ �ℎ � 푓 푥 푓 푥 푖 푛 푖=1 푡 푡 푡 푡 푖 푖=1 푖=1 = . = . For (a constant, ) 푖 voltage ( U) and a constant 푡( +∗ 푡current∗ ( )/2,( I),, the) power( is( )constant,) ( =(+ +. 푖)/2)/2 =ℎ 1,2,∆푥 … , 푖 푖 푖 푖 푖 푖 푖 푖−1 푖−1 퐴 퐴 ℎ ℎ � � 푓 푓 푥푥 푖 = 푥 푛푦 ( ). 푓 푥 푦 푦 푖=1푖=1 For time-dependent=ℎ 1,2,∆푥 … , values 푥 of∗ 푦 voltage = and((= ,푓current,,. 푥 ) ). ( ) ( ) and ( ( 푦 ))( ) 푦,, the ∗ power ( ∗( ++ is also))/2 /2time- 푖 푖 푖 ∗ 푖 푖−1 푖 푖푖 푖 푖 푖 푃 푖 푈퐼푖 푖−1 푖−1 푃 푈퐼 푃 푈퐼 dependent.푥 Instantaneous푦 =푓 power푥. 푖is( then) calculated 푦 푦( ),푥 as 푦푥 푦 ( ) = ∗ ∗ =( 푓)=(푥푓. ) . 푥 Both. ( ) ( ) 푦and 푦 푦( ) 푦, 푖 퐴푛 ℎ1 �1 푓 2푥 2 푖푖 푖푖 푖푖 푖푖 푖−1푖−1 푖 푛 푡 푖=1푡 푡 푡 푃 푃푈퐼 푈퐼 푢 푡푢 푡 푖 푡 must be defined= 푛 and( )available. between 푥푥 and 푦 푦 . In our 푓example,푓 푥푥 the voltage푦푦 푦 푦is constant ( , ) ( ) 푡 1 푡(2 + 푃 )푈퐼/2 푢 푡 푖 푡 푡1 1 푝푡2푡 2 푃푢 푡 푈퐼푖 푡 푢 푡 푖 푡 = 푛 ( ). ∗ 푡 푡 푃 1푈퐼 2푢 푡 while∗ the current is not, as it depends on 1the1 states22 of the switches S and S . The energy 푖 푖 푖 푖 ∗ 푖푖−1 푡푡 푡푡 푥 푦 푓 푥 퐴 ℎ �푦 푓푖 푥푦 == . . = consumed. 퐴 ℎ( �by) 푖=1the 푓 푥 loads ( ) ,in the (circuit) = is( ) ( ). ( , ) ( ) ( + 푖=1)/2 ( , ) ( ) ( + )/2 푡1 푡2 ∗ 푃 푈퐼 푢 푡 푖 푡 푝 푡 푢 푡 푖 푡 푃푃 푈퐼푈퐼 푖 푖 ∗ 푖 푖 푖−1 푖 푥 푖 푦 =푓푖 푥. ( ) 푖 푦 푖−1 푦( ), ( ) = ( ) ( ). 푥 푦 =푓 푥. ( ) 푦 푦(=) , 푡2 ( () ) == (푡2 ) (( )). ( ) = 푡2 ( ) . 푡1 푡2 푃 푈퐼 푢 푡 푖 푡 푝 푡 푢 푡 푖 푡 푡1 푡2 푃 푈퐼 푢 푡 푊푖 푡 � 푝 푝푡 푡푑 푢�푡푢푖 푡푡 푖 푡 푑푡 푈 � 푖 푡 푑푡 = 푡2 ( ) =푡1 푡2 ( ) ( ) 푡1 = 푡2 ( ) . 푡1 = 푡2 ( ) The= average푡2 ( ) ( power) = is obtained푡2 ( ) as. energy divided by T, 푊 � 푝 푡 푑푡 � 푢 푡 푖 푡 푑푡 푈 � 푖 푡 푑푡 푊 � 푝푡1 푡 푑푡 � 푢푡1 푡 푖 푡 푑푡 푈 � 푖푡1푡 푑푡 푡1 푡1 1 푡1 = 1= 푡2 ( ) , = = 푡2 ( ) , 푊 푃푊 푈 � 푖 푡 푑푡 푃 푇 푈푇� 푖푡1푡 푑푡 푇 푇 푡1 where = .

푇 푡2 − 푡1 4.3. Solution

Two flashlight bulbs were used as loads and connected to the power supply unit (PSU) through the MAX471 IC (Fig. 5), which measures the current that flows through it and converts it to voltage on its OUT pin, at the ratio of 1V/A. The voltage at the PSU was set to 3.5V. By switching the lights on and off during measurement, a series of varying current readings was obtained.

Fig. 5. Setup for the current measuring experiment ( , ), ( (, ,),…,), ( ,, ),,…, =( 1,2,, …), = 1,2, …

0 0 1 01 0 1푛 푛1 푛 푛 (푥 , 푦 ), (푥 ,푥(푦 ),푦,…,),((푥 ,,푦 )),,…, 푛 =(푥 1,2,, 푦 …), 푛= 1,2, …

0 0 1 1 푛 푛 푥0 푦0 푥1 푦푥1 푦 푥푥푛 푦푦푛 푛 푥 푦 푛 ( , ), ( , ),…,=( 1 , ), == 1 1,2, … 0 0 1 1 푛 푛 푛 푛 ( )( ( ) )( ) (푥 , 푦( ),=(푥 , 푦 ),…, (푥+, 푦 ), 푛 = 1,2,= …+ . ( ) = + = + ( , ), ( . , ),…, ( , ), = 1,2, … 1 10 0 0 1 0 0 1 0 0 0 1 1 푛 푛 1 0 푥1 − 푥 01푥푥 − − 푥 푥 1 0푥 − 푥 − 푥 0 푦 −푥 푦− 푥 푦 − 푦 푥퐿 푦푥 푥푦 푦 =푥 1 푦푦 푛 푦 0 0 1 1 푛 푛 퐿 푥 푦 0 1 푦 01 10 푦 1 0 1 푥 푦0 푥 1 푦 0 푥 푦 푛 푥 − 푥 푥푥 −−0 푥 푥 푥 −0 푥 푥 (− 푥, ), ( 푥 , −) 푥,…, ( , ), = 1,2, … 푛 ( )( ) 푥0 푦0 푥1 푦1 푥푛 푦푛 푛 ( ) = + 푉 = + 푉 . = 1 1 0 0 1 0 1 0 푥 − 푥 1 푥 − 푥 0 푥 − 푥 푦 − 푦 퐿 푥 푦 0 1 푦 1 푢 0 푦= 1023푢 /51 0 푛 ( )( ) 푥 − 푥 =푥 1023−0 푥 /5 ( ) =푥 − 푥 + = + . ( , ), ( , ),…, ( , ), = 1,2,1 … 0 0 1 0 푥 − 푥 푥 − 푥 푥 − 푥 푦 − 푦 = 0.5 = 0.5 = 4.5 = 4.5푎 푢 푎 1 푢 0 1 0 푉 퐿 푥 푦 0 1 푦 1 0 푦 1 0 푥0 푦0 푥1 푦1 푥푛 푦푛 푛푥 − 푥 푥 −0 푥 푥 − 푥 1 2 ( , ), ( , ),…, ( , ), = 1,2, … 푢1 푢 푢2 푢 = 102 = 102 = 921 = 921= 1023푢 /5 푥0 푦0 푥1 푦1 푥푛 푦푛 푛 푉 1 2 = 1 푎1 푎 푎2 푎 4( 102) = 0.5 = 4.5 푎 4( 푢102) ( ) = ( ) = . . 푢 273 푛 273 ( )( = 1023) /5 1 2 ( ) = +푎 − 푎= − + . 푢 = 102 푢 = 921 푟 푎 1 푟 푎 0 0 푎1 0 푢 1 0 푥 −= 푥 0.5 1 푥 − 푥 =0 4.5 푥 − 푥 푦 − 푦 1 2 퐿 푥 푦 0 1 푦 1 0 푦 1 0 푎 푎= 1023 /5 푥 1− 푥 4( = 0.5푥102 − ) 푥 2 = 4.5푥 − 푥 푥 푦 푥 푦 ( 푢) == 102 . 푢 = 921 273 = 푛 1( )= 푛 ( ) 2 푢 = 102 푎 푢 = 921 1 푢 푎 − 2 푢 푟 푎푎 ∗ 푎 ∗ 4( 102) ( , 푖 ), ( 푖 , ),…,푖 ( 푖 , ), = 1,2, … 1 2 퐴 � 푓 푥퐴 ∆푥� 푓 푥 ∆푥 ( ) = . 푎 푎 푖=1 4푖=1( 102) 273 = ,=0 ( 0) =[ 1 , 1, ]. [. 푛 ,푛 ]. 푎 − 푥 푦 푥( ,푦 ), (푥 ,푦 ),…, (푥 , 푦 ), 푛= 1,2, … ∗ 273∗ 푟 푎 푖 푖 = 푖−1 푛 푖 ( 푖푖 ) 푖−1푖−1 푎 − 푖 푖 푖−1 푖 ∆푥 푥 − 푥∆푥=푟0푥푎푥 0,−∈ 푥푥1= 1푥푥 ,∈ 푥푛 푛푥 푥 푦∗ 푥 푦 =푥 1 푦 푛 푥 ∗ 푦푖 ∗푖 퐴 � 푓 푥 ∆푥푖 푖−1 푖푖=1 푖−1 푥 =푥 푥 =푥 = 푛 ( ) 푥 푦 = , [ , ]푛. ( )( ) ∗ ( ) = ∗ ∗ + = + ∗ . 푖 푖= 푛 푖 ( )푖 푖 푖 ∆푥푖 푥푖 − 푥푥푖−1 +푥푥푖 ∈1 푥푥푖−1+푥푖 0 퐴 �0 푓 푥1 ∆푥0 = = 푥 −, 푥 .= ∗푥 − 푥. 푥 −푖=1 푥 푦 − 푦 1 0 1푖2 푖 0= , [ , ]. 퐿 푥 ∗푦푖 퐴20 푖−1�∗ 1 푓푦푖푥 1∆푥푖−1 0 푦 1 0 ∗ 푥 − 푥푖=1 푥 푥푥 − 푥 푥 − 푥 푖 푖 푥 푖−1푥 푖 0 ∗ 푥 푥 = =푥 푥 , [ , 푖]. 푖 푖−1 푖 푖−1 푖 = ( + )/2. ∆푥 푥 − 푥 푥 ∈ 푥 푥 = ( ∗+ )/2. ∗ = , ∗ 푖 푖 푖 푖∗ 푖−1 푖 푉푖−1 푖 ∗ ∆푥 푥푖 푥+푥−푖−1푖 푥 = 푖 푥 ,∈푖−1 푥 푥 푥푖 =푥 푥푥 . 푥 푥 푥푖 푥푖−1 = . = . 2 ∗ = 푥푖+푥푖−1 ∗ 푖 푖−1푖 푖−1 푢 ∗ 푥푖+푥푖−1 ∗ 푥 푥 = 1023 /5 ∗ 푖 푖 푥 =푥 푖 푖 푥푖 2 푥 2 푥 푥 +푥 = ( =+ )/2.∗ = = . 푖 푎푖 = 0.5푢 ∗ 푥 +푥 푖 2 푖−1 푖 푖−1 ∗ 푖 푖 = 푖 . 푖 푥 푥 = . 푥 =ℎ푥 1,2,∆푥 …푥 , =ℎ 1,2,2∆푥 …1 , 푥 ∗ 푖 푖−1푢 = 4.5 = ( + )/2. ∗ 푥푖+푥푖−1 푖 푥 푥 푖 푥 ∗ 푥 2 푖 =푛 (푖 + 2)/2.푛 푖 푖 푖−1 = 푢 = 102 푥 푥 푥 = = 푛 ∗ ( . =). 푛 ( ). 푥푖+푥푖 푖−1 푖 푖−1 = . ∗ 푥 푖 ∗푥 푥 1 ∗ 푖 =ℎ 1,2,∆푥2 … , 푖 푎 푖 푥푖+푥푖−1 퐴푥 ℎ � 푓 퐴푥 ℎ � 푓 푥= 921 ∗ = =푖=1 1,2, … , 푖 푖=1 Đ. Herceg, D. Herceg ( , ) 푥 ( , )2( ) ( (246) + ) /2 ( + )/2 2 = = 1,2, … , 푖 푖 푛 푎 4( 102) ∗ ∗ ℎ ∆푥 푖 푛 푖 푖 푖 푖 푖 푖 푖 푖−1= 푛 푖 ( 푖−1). ( ) = . 푥 푦 푥 = 푦 푓푖 푥. (=푓) 푥. 푦 The 푦(( ))data, 푦 for ( )푦( =) , was( ) sampled( ). 273 by the Arduino,= 푛 the( values). were relayed to a PC and ℎ ∆푥 푖 푛 ∗ 푎 − 푖 ∗ 1 2 saved퐴 in aℎ file. � 푓 =Then,푥 푟푛 the푎 ( power). P was calculated by approximating the definite integral 푡1 푡2 푡푃 푈퐼푡 푃푢 푡 푈퐼 푢푖 푡푡 푖=1푝 푡푖 푡 푢 푡 푖 푡 퐴 ℎ � 푓 푥푖 ( , ) ( ) by( using+ one)/2 of the numerical∗ methods described푖=1 above. ( , ) ( )푖 ( + )/2 ∗ = 푡2 ( ) A= simple푡2 ( C++ )퐴 ( ) program ℎ � = 푓 푥 푡2was ( )used . to read the analog input in 1/4 second intervals and 푖 푖 푖 푖 푖−1 푖=1 ∗ 푥 푥 푦 ( , =) 푓 푥 . (( ) ) 푦 푦 ( 푖 ) ,( 푖 + ( ) )=/2 ( )푖 ( ). 푖 푖−1 print it푥 to 푦the serial port.푓 푥Another program푦 was푦 written in C# to collect the data from the 푊 � 푝∗ 푡 푑푡 � 푢 푡 푖 푡 푑푡= 푈. � 푖 푡(푑푡) ( ), ( ) = ( ) ( ). 1 2 푖 푖 푡1 푖 serial port푡1 on푖 the푖−1 PC and 푡1save푦 it into a file. With the program running, lightbulbs were 푡 푡 푥 푃 푦 푈퐼 =푢푓 푡푥. ( 푖) 푡 푦 푝푦( 푡), 푢 푡( 푖)푡= ( ) ( ). connected푡1 1and푡2 disconnected푃 푈퐼= 푛 several푢( 푡 ) times. 푖Raw푡 data푝 was푡 converted푢 푡 푖 푡 to the range from 0V = 푡2 ( )= = =푡2 ( )푡2( () ) =, 푡2 ( ) . 1 2 5 ∗ to V using linear interpolation= in 푡2 푖the( same푖) = way푡2 as( in) the( ) previous= 푡2 exercise.( ) . The data was 푡 푡 푃 푈퐼 푢 푡푊 푖 푡 퐴푝 푡� 푓푢푥푡 푖∆푥푡 scaled and graphed in Mathematica푖=1 (Fig. 6). 푊 � 푝 푃푡 푑푡 푡2 � 푢푈푡 �푖 푡푖푡2푡푑푡푑푡 푈 � 푖 푡 푑푡 푡2 = 푇 ( 푇) 푡1= = ( ) ( ) , = [ ( ), .] . 푡1 To calculate푡1= the average푊푡1 power,� 푝 the푡 푑푡definite� 푢integral푡 푖 푡 푑푡 in 푈 � 푖 푡 푑푡 1 푡1∗ 푡1 푡1 푊 � 푝 푡 푑푡 푖� 푢 푖푡 푖 푡푖−1푑푡 푖푈 � 푖푖−1푡 푑푡푖 = = 2 ∆푥푡21 ( )푥 −, 푥 = 푥 ,∈ 푥 푥 1 푡1 푇 푡 − 푡 푡1 푡1 = = 푡2 ( ) , 푊1 ∗ 1 푖 푖−1 푃 = =푡2푈 �( )=푖 푡 푑푡 푡2푥 ( =)푥 , 푊 푇 푇 푡1 푃 푈 � 푖 푡 푑푡 = 푊 ∗ 푇 푇 푡1 푃 푈푃 � 푖 푡 푑푡 푈 � 푖 푖 푡 푑푡 푖 = 푇 푡1 푥 +푥 2 푇 1 푇 푡1 = . 푇 푡 − 푡 = 2 2 1 was approximated1 with the∗ trapezoidal푖 푖−1 rule.푇 Since푡 −the 푡 raw data was sampled at regular = 푡2 ( ) 푖 푥 푥 1 1/4s intervals, the푇 equidistant푡2 푥− 푡1 form of the trapezoidal= 푡2 ( rule) was used, 1 = ( + )/2. 푃 푈 � =푖 푡 푑푡 ∗푡2 ( ) 푇 푡1 푥푖 푥푖 푥푖−1 푃 푈 � 푖 푡 푑푡 = . + 푇 푡1 ∗ 푥푖+푥푖−1 = 푛 푃 푈 � 푖 푡 푑푡 + 푖 2푇 푡1 = 푛 푥 2 푖 푖−1 푦 푦 + = 푖 2 푖−1 퐴 ℎ � = 푛 푦 푦 푖=1 푖 2 푖−1 퐴 ℎ � 푦 ℎ푦 ∆푥푖 푖=1 since = 퐴= 1/4ℎ � for = 1,2, … , . The power P was obtained as 푖=1 = = 1/4 ℎ ∆푥푖 푖 푛 푖 1 1 + ℎ ∆푥 20� = 2.19226 4 2 푦푖 푦푖−1 푃 ≈ 푈 � 푊 푇 푖=1

Fig. 6. Converting raw data and graphing the results ( , ), ( , ),…, ( , ), = 1,2, … ( , ( ), (( ),,,( )),…,,, ( )(,…,, ,)(,…,), ( )=, , 1,2,)=, … 1,2, = … 1,2, …

0 0 1 1 푛 푛 0 00 010 101 1 1 푛1 푛푛 푛 푛 푛 (푥 , 푦 ), (푥 , 푦 ),…, (푥 , 푦 ), 푛 = 1,2, … (푥 , 푦(푥), (푦(푥푥),,,푦(푦푥)),…,,,푦(푥)(,…,,푥푦,)(푦,…,푥), 푦 ( 푛푥)=, , 푦 푛 1,2,)=, … 1,2,푛 = … 1,2, …

0 0 1 1 푛 푛 0 00 010 101 1 1 푛1 푛푛 푛 푛 푛 푥 푦 푥 푦 =푥 1 푦 푛 푥 푦푥 푦푥푥 푦푦푥 푦 푥=푥 1푦 =푦푥 1 =푦푛푥 1 푦푛 푛

푛 ( )( ) 푛 푛 푛 ( ( )(( )( )() ) ) ( ) = + = + ( .) =( ) =( ) = + + + = =+ =+ + . . . 1 0 0 1 0 1 1 1 0 0 0 0 01 100 10 0 1 0 푥 − 푥 1 푥 − 푥 0 푥 − 푥 푦 − 푦1 1 01 푥 −0 푥 −0 푥푥 −1 푥 푥 −1 푥 −1 푥푥 −0 푥 0푥 −0 푥 − 푥푦푥 −−푦 푥 푦 −푦 푦 − 푦 ( , ), ( , ),…, ( , ), = 1,2, … 퐿 푥 푦 푦 푦 퐿 푥퐿 푥푦퐿 푥푦 푦 푦 푦 푦 푦 푦 푦 푥0 − 푥1 푥1 − 푥0( ) ( 푥)1 − 푥(0 ) 푥0 −푥 푥01−푥 푥01 −푥1 푥1−푥 푥10−푥 푥10 − 푥0 푥1 −푥 푥10−푥 푥10 − 푥0 = 1023 /5 = 0.5 , , = , 4.5 ,…, = 1023 , = 1023, =/5 1023 = /5 1,2, /5… = 0.5 = 0.5 = 0.5 = 4.5 = 4.5= 4.5 0 0 1 1 푛 푛 (푥 , 푦 ), (푥 , 푦 ),…, (푥 , 푦 ), 푛 = 1,2, … 1 0 0 2 1 1 푛 푛 푢 푎 푢 푢 (푥 푦 )푢푢(푥 푢푦 ) 푢푎 (푥푎 푦 )푎푢 푛 푢 푢 푢1 푢1 푢1 푢2 푢2 푢2 = 102 = 921 , , =, 102=,…, 102 = 102 , , = = 921 1,2,= 921 …= 921 0 0 1 1 푛 푛 푥 푦 푥 푦 =푥 1 푦 푛 1 2 0 0 1 1 11 1 푛 푛 2 2 2 푎 푎 4( 푥 102푦 )푎 푥 푎푦 푎 =푥 1 푦 푎 푛 푎 푎 4( 4(1024()102)102) ( ) = . ( ) =( ) =( ) = . . . 푛 ( )( ) 273 273273 273 ( ) = + = + . 푎 − 푛 ( )( ) 푎 − 푎 − 푎 − 푟 푎 ( ) = + = + 푟 푎 푟 푎. 푟 푎 푥 − 푥1 푥 − 푥0 푥 − 푥0 푦1 − 푦0 1 0 1 0 1 0 0 1 0 퐿 푥 푦 0 1 푦 1 0 푦 1 0 1 0 푥 − 푥 1 푥 − 푥 0 푥 − 푥 푦 − 푦 = 1023 /5 푥 − 푥 = 0.5푥 − 푥 = 4.5푥 − 푥 퐿 푥 푦 푦 푦 푥 푦 푥0 − 푥1 푥 푥1푥푦− 푥0푦 푦 푥1 − 푥0 = 1023 /5 = 0.5 = 4.5 1 2 = 푛 ( ) = 푛= (푛 =)(푛 ) ( )푢 = 102 푎 푢 = 921 푢 푢 푢 푎 푢 ∗ 푢1 푢2 ∗ ∗ ∗ = 102 = 921푖 푖 푖 푖푖 푖 푖 퐴 � 푓 푥 ∆푥 퐴 퐴� 푓�퐴푥 푓�∆푥푥 푓∆푥푥 푎∆푥1 푎2 푖=1 푖=1 푖=1 푖=1 4( 102) 1 = 2 , [ , ]. [ [ ] [ ] ] ( ) = . 푎 푎 4( 102) = = = , , , , . , . , . 273 ∗ ( ) = . ∗ ∗ ∗ 푎 − ∆푥푖 푥푖 − 푥푖−1 푥푖 ∈ 푥푖−1 푥푖 273 ∆푥푖 푥푖 푖 − 푥푖푖푖−1 푖푖−1푥푖 ∈푖−1푖푥푖−1 푖푥푖−1푖 푖−1푖 푖 푟 푎 = , 푎 − ∆푥 ∆푥푥 −=푥 −= 푥, 푥=,∈ 푥푥,∈ 푥 푥 ∗ 푟 푎 ∗ ∗ ∗ 푖 푖−1 푖 푖 푖−1 푖푖−1 푖−1 푥 =푥 푥 푥=푥 = 푥푥 =푥 푥 푦 푥 푦 ∗ ∗ ∗ ∗ = 푛 ( ) 푥푖 +푥푖 푥푖 +푥푖 푖 +푖푖 + 푖 = 푛 ( ) 푥 푥푥 푥 ∗ = . = = = . . . 푖 푖 퐴 � 푓 푥 ∆푥 푖 2 푖−1 ∗ 푖 2 푖푖−12 푖푖−12 푖−1 ∗ 푥 푥 푖 푖 ∗ ∗ ∗ 푖=1 푖 퐴 � 푓 푥 ∆푥 푖 푥푖 푥푥푖 푥 푥 = , [ , ]. 푥 푖=1 푥 푥 푥 = ( + )/2.= , [ , ]. = ( =+ ( =+ ()/2.+ )/2. )/2. ∗ 푖 푖 푖−1 푖 푖−1 푖 ∗ ∗ ∗ ∗ ∗ ∆푥 푥 − 푥 = 푥 ,∈ 푥 푥 푖 푖 푖−1 푖 푖 푖−1 푖 푖−1 푖 푖 푖 푖 푖 푖푖−1 푖푖−1 푖−1 = . 푥 푥 푥 ∆푥 푥= −= 푥 =.= 푥. ,∈ 푥. 푥 푥 푥 푥 푥 푥푥 푥 푥 ∗ 푖 푖−1 ∗ 푥푖+푥푖−1 ∗ 푥∗푖+푥∗푖−1푥∗푖+푥푖−1푥푖+푥푖−1 푥 =푥 푖 푖 푖 푖 푖 푖−1 푥 2 푥 푥 푥2푥 =2푥 2 ∗ = = 1,2, … , = = = = 1,2, = …1,2, ,=… 1,2, , … , 푖 푖 ∗ 푥 +푥 푖 푖 = . ℎ ∆푥푖 푖 푛 ℎ ℎ∆푥푖 ∆푥푥ℎ 푖 +푖∆푥푥 푖 푖 푖 푛 푛 푛 2 = . ∗ 푖 푖−1 푖 푥 푥 = 푛 ( ). 푖 2 푖−1 = =푛 =(푛 )(. 푛 ). ( ). 푥 ∗ 푥 푥 = ( + )/2. ∗ 푥푖 ∗ ∗ ∗ 퐴 ℎ � 푓 푥푖 = ( + )/2. 퐴 퐴ℎ �ℎ퐴 푓 �푥푖ℎ 푓 �푥푖 푓 푥푖 ∗ 푖=1 푖=1 푖=1 푖=1 푖 푖 푖−1 ( , ) ( ) ( + )/2 ( , (∗ ) , () , ) ( )( ) ( ) ( +( +()/2+)/2 )/2 = . 푥 푥 푥 푖 푖 푖−1 ∗ = . 푥 푥 푥 ∗ ∗ ∗ ∗ 푥푖+푥푖−1 푖 푖 푖 푖 푖−1 푖 푖 푖 푖 푖 푖 푖 푖 푖 푖 푖푖−1 푖푖−1 푖−1 푖 푥 푦 푓 푥 (푥푖+푥푖−1푦) ( 푦 ) ( )푥 푦 푥 푦 푓 푥 푓 푥 푦 푦 푦 푦 푥 2 = . ∗ ( ) , , (, ), ,…, ( ) ,= ( , ) 푥( = ) 푦 . 1,2, … = = . 푓 푥 =. ( ). ( ) ( 푦) ( ) , 푦( ) , ( ( ) ), = ( ) (=() )((=)). (() ). ( ) . = 1,2, … , 푥푖 2 1 2 = 0 0 =1 1,2,1 … , 푛 푛1 1 2 1 2 2 푡 푡 푃 푈퐼 푢 푡푥( ,푦 ), (푥푖 푡,푦 ),…,푝(푥푡 , 푦푡푢), 푡 푛푡푖=푡푡 1,2,푡 푡 …푃 푡 푃푈퐼 푈퐼푃 푢푈퐼푡 푢 푡 푢 푡푖 푡 푖 푡 푖푝 푡푡 푝 푡푢푝푡 푡푢푖ℎ 푡푡 푖푢∆푥푡푡푖 푖 푡 푖 푛 푖 ℎ =∆푥 푡2 ( ) 푖 = 푡2 ( 푛) ( ) = 푡2 ( ) . = 푡2= (푡2=) ( 푡2=) (푡2=) (푡2)=(( 푡2)) ((=)) (=)푡2 (=푡2) (. 푡2) (. ) . = 푛 ( ). 푥0 푦0 푥1 푦1 푥푛 푦푛 푛 = 1 = 푛 ( ). ∗ 푖 푊 � 푝 푡 푑푡 � 푢 푡 푖 푡 푑푡 푈 � 푖 푡 푑푡 ∗ 푊 푊� 푝푊�푡 푝푑푡�푡 푑푡푝�푡 푢푑푡�푡 푢푖 푡�푡 푑푡푖푢푡푡푑푡푖푈푡�푑푡푈푖 �푡 푑푡푈푖 푡�푑푡푖 푡 푑푡 퐴 ℎ � 푓 푥 푡1 푡1 푡1 푡1 푡1 푡1 푡1 푡1 푡1 푡1 푡1 푡1 푖=1 푛 퐴( ℎ �)( 푓 푥푖 ) ( , ) ( ) ( + )/2 ( ) = + 1 = + 푖=1 . 1 1 1 ( , ) = (= ) 푡2 ( ) ( , + )/2 = == == 푡2=( 푡2) (, 푡2) (, ) , ∗ ( 푥 −, 푥1), ( , 푥) −,…, 푥0 ( , ), 푥 −= 푥0 1,2,푦1 …− 푦0 푖 푖 푖 푖 푖−1 1 0 1∗ 0 푥 푦 =푓 푥. ( ) 푦 푦( ), ( ) = ( ) ( ). 퐿 푥 푖 푖푦 0 1 푊 푦 푖 1 0 푦 푖 푖−1 1 0 푊 푊 푊 푥 푦 푥 0 −푃 0 푥=푓 1푥. 푥 1 푈 − 0� 푥( 푖) 푡 푛 푑푡 푦 푛 푦( ), 푥 − 푥( ) = ( ) ( ). 푃 푃 푃 푈 �푈푖 �푡 푑푡푈푖 푡�푑푡푖 푡 푑푡 푥( ,푦 ),푇(푥 ,푦푇 ),…,푡1 (푥 , 푦 ), 푛= 1,2, … 푇 푇푇 푡1푇푇 푡1푇 푡1 1 2 = ( =, )=, ( = , ) ,…,푡( , 푡 ), 푃= 1,2,푈퐼 … 푢 푡 푖 푡 푝 푡 푢 푡 푖 푡 1 2 푡 푡 0 푃0 푈퐼1 1 푢푉 푡 푛 푛 푖 푡 푝 푡 푢 푡 푖 푡 = 푡2 ( ) = 푡2 ( ) ( ) = 푡2 ( ) . 푥 푦 푥 푦 2 1 푥 푦 푛 0 02 211 112 1 푛 푛 푇 푡 − 푡= 1 푇푥( ,푦푇푡 )−, (푡푇푥 푡 −,푦푡 )−,…, 푡 (푥 , 푦 ), 푛= 1,2, … 1 = 푡2 ( ) = 푡2 ( ) ( ) = 푡2 ( ) . 1 1 1 = = 푡21023푢( ) /5 Arduino and Numerical Mathematics= = 푡2=( 푡2) ( 푡2) ( ) 247 푊 � 푝 푡 푑푡 � 푢 푡 푖 푡 푑푡 푈 � 푖 푡 푑푡 푛 0 0 1 1 푛 푛 푡1 푡1 푡1 푊 � 푝 푡 푑푡 (� 푢 푡 )(푖 푡 푑푡 )푈 � 푖 푡 푑푡 푥 푦 푥 푦 =푥 1 푦 푛 ( ) = + 푡1 = + 푡1 . 푡1 1 푃 1 푎푈 �=푖 0.5푡 푢0푑푡 0 1 0 푃 푃 푈 �푃푈푖 �푡 푑푡푈푖 푡�푑푡푖 푡 푑푡 = = 푡2 ( ) , 1 0 푥 − 푥 푇 1푡1푥 − 푥 0 푥 −1 푥 푦 − 푦 푇 푡1푇 푡1푇 푡1 푛 ( )( ) 퐿 푥 푦 푦 푦= = 푡2 ( ) , 0 1 1 1 + 0 1 0 ( ) = ++ + + = + . 푊 푥 −= 푥 푛푢 푥 −0 푥 푥 − 푥 = =푛 =푛 푛 푃 푈 � 푖 푡 푑푡 = 4.5 푊 1 0 0 1 0 푖 2 푖−1 푥 − 푥푖 2 푖−12 푥 −2 푥 푥 − 푥 푦 − 푦 푇 푇 푡1 푦 푦 푃 푈 � 푖 푡 푑푡 1 0 푦 푦푦푖 1푦푖푖−1 푦푖−1 0 = 2 푉 푇 푇 푡1 퐿 푥 푦 0 1 푦 1 0 푦 1 0 퐴 ℎ �푢 = 102 퐴 퐴ℎ �푥 ℎ퐴− � 푥 ℎ � 푥 −0 푥 푥 − 푥 푖=1 = 푖=1 푖=1 푖=1 2 1 = = 1/4 = = = 1/4== 1/4 = 1/4 푇 푡 − 푡 1 푢 2 1 1 푎 ==1023921 /5 푇 푡 − 푡 푉 = 푡2 ( ) 푖 1 1 + 푖 1 푖 푖 1 1 11 +1 + + ℎ ∆푥 20� = 2.ℎ19226ℎ∆푥 ∆푥ℎ ∆푥 20� ( , ), ( , ),…, ( , =),Fig. 7.푡2= Numerical 1,2,( ) … integration in Mathematica 20� 20� = 2.=19226 2.19226= 2. 19226 4 푖 푎2 푖−1 푢 4 4 푖 42 푖푖−12 푖푖−12 푖−1 푦 푎 푦4( = 0.5102 ) 푦 푦푦 푦 푦= 1023푢 /5 푃 푈 � 푖 푡 푑푡 푇 푡1 푃 ≈ 푈 푥0�푦(0 ) =푥1 푦1 푥푛. 푦푛푊 푛 푃 ≈푃 ≈푈 푃푈� ≈ �푈 � 푊 푊 푊 푇 ( 푖=1, ), ( , 1 273),…, ( 푃, ), 푈 �= 1,2,푖 푡 푑푡 … 푇 푖=1푇푖=1 푖=1 + 푢 푇 푡1 푇 where is푎 the= − 4.5 sample at index = , 209= 209/4 =/452 =.2552 . 25 and = 3.5= 3.5푎. The =calculation 0.5푢 in = 푛 0푟 푎0 1 1 푛 푛 + 푖 2 푖−1 푥Mathematica푦 푥푖 푦 is shown=푥 1 푦= in Fig.푛 7. 2 푖 푖 푖 1 푦 푦 푦 푢 = 102푦 푦 푖 푦푖 푇푖 푖 2푇 푖−1푠 푠 푈 푈 푉 푢푉 퐴 ℎ � 푦 푦 = 4.5 푖=1 푥 푛 퐴 ℎ �( )( ) = = 1/4 ( ) 1 푖=1 2 = == 1/4 +푎 = 921 = + . 푢 = 102 5. Numerical1 Differentiation0 and0 Curve1 0 Smoothing 푖 1 1 + 푥 − 푥 푦 푥 − 푥 푥 − 푥 푦 − 푦 ℎ ∆푥 20� = 2.19226 1 푖 0 2 1 1 1 0 + 퐿 푥 푦 0 1 푎 푦 1 0 푦 1 0 1 4 푖 2 푖−1 ℎ ∆푥 = 푛 4(( ) 102 )20� = 2.19226 푎 = 921 푥 −( 푥 ) = 푥 −0 푥 . 푥 − 푥 푦 푦 Finite difference∗ formulas4 푖 for2 푖−1numerical differentiation are approximations of deriva- 푃 ≈ 푈 � 푊 273 푖=1 � � 푦 푦 2 푇 tives퐴 at� a point. 푓푃푥 ≈푎 − ∆푥They푈 � are used to calculate the푊 value of the first derivative푎 4( of a 102 function ) = 209 /4 = 52.25 = 3.5 푟 푎�=1 푇 푉 푖=1 == 209 /4, = 52 .25[ , ]. = 3.5 ( ) = . for a given , or when the function is unknown and only sampled data 푖is273 available. ∗ 푦푎, −( 푖) 푇 ± 푠, ( ± ) 푈 푉 � Geometrically,� �−1 = 1023 a푢 finite�−1/5 � difference is the slope of a secant through and 푖 ∆푥 푥� 푟 푎 푦 , ( 푖) 푇 푥±− 푥푠, (= ±푥 ),∈ , which푥 푥 approximates푈 푉 the value of the first derivative at , ∗ �푥 푓 푥 � �푥 ℎ 푓 푥 ℎ � 푎 �−1 = 0.5푢 푥� 푥푦 �푥 푓 푥 � �푥 ℎ 푓 푥= (ℎ �± ) ( ) 푥 ( )∗ 1 . � 푢� = 4.5 � 푥 +푥 푦 = 푓 푥 . ℎ − 푓 푥 푓 푥 ≈ 2 2( ± ) ( ) ∗ ( �) 푢�−1= 102ℎ . A� symmetric푥 푥 difference can also be used, 푥 � = ( + 푓1 )/2.푥 ℎ − 푓 푥 푓 푥 ≈푎 = 921 ∗ ( + ) ℎ ( ) � ( )� �−1 . = . 푥 푥 푥 2 2 � 푎 4( 102) 푥�+푥�−1 푓 푥 ℎ − 푓 푥 − ℎ ∗ 푓 푥 (≈) = . 푥� 2 273ℎ As =gets smaller, 푎 − the accuracy of the approximation increases, i.e. secant approach- 푟 푎 es the tangent at . ℎ ∆푥� 푥 5.1. Real World Example 푦 In engineering practice there are many instances where voltage change rates must be measured and calculated, e.g. electric car applications (Kim et al., 2014) or early failure detection in electronic components (Sathik et al., 2018). Since battery charg- ing and discharging may take a long time, it is impractical for a classroom exercise. A capacitor charging experiment may therefore be a good substitute. The aim of this exercise is to illustrate how the voltage change rate can be calculated by means of numerical differentiation. As capacitor charging and discharging are asymptotic pro- cesses, we can decide to stop charging when the voltage change rate drops below a certain threshold. 248 Đ. Herceg, D. Herceg

Fig. 8. Schematic for the capacitor charging experiment

( , ), ( , ),…, ( , ), =( 1,2,, …) , ( , ),…, ( , ), = 1,2, … Capacitor C is charged through a resistor. After charging, it is discharged through an- 0 0 1 1 푛 푛 0 0 1 1 푛 푛 푥( ,푦other), (푥 resistor,푦 ),…, and(푥 a, 푦red), LED. 푛= 1,2, The푥( …,푦 circuit ), (푥 ,is푦 presented),…, (푥 , 푦in) Fig., 푛 =8. 1,2,The …user can choose be- tween charging and discharging by toggling the switch S. The voltage on C is measured 0 0 1 1 ( ± 푛 ) 푛 ( ) 0 0 1 1 푛 푛 푥 푦on Arduino.(푥 )푦 Calculate=푥 1 푦 and푛 graph. 푥 the푦 charging푥 푦 rate= of푥 1 the푦 capacitor푛 over( ± time.) Establish( ) a ( ) . computable� stopping condition for charging, based on the voltage change rate. 푓 푥 ℎ − 푓 푥 � 푓 푥 ℎ − 푓 푥 푓During푥 ≈ charging,푛 the voltage( )(across the) capacitor푛 depends( on R,)( C and input) voltage ( ) = + ( + ) =ℎ ( (+) =) + . = 푓+ 푥 ≈ . ( ) . ( + ) ℎ ( ) U according1 to the0 formula 0 1 1 0 0 ( ) 0 1 0 . 푥 − 푥 푥 − 푥 2 푥 − 푥 푥 −푦 푥− 푦 푥 − 푥 푥 − 푥 푦 − 푦 1 0 � 푓1 푥 ℎ − 푓01푥 − ℎ 0 ( ± 1 ) ( ) 0 2 퐿 푥 푦 0 1 푦 1 0 푦퐿 푥 푦( 1)0 0 1 푦 1 0 푦 � 푓 푥1 ℎ0 − 푓 푥 − ℎ 푥 −푓 푥푥 ≈ 푥 −0 푥 / 푥푥−− 푥 푥 푥 −0 푥 . 푥 − 푥 ( ) = (1 ℎ ). 푓 푥 ≈ / � ( ) = (1 ℎ ). −푡 �� 푓 푥 ℎ − 푓 푥 � 푓 푥 ≈ −푡 푅퐶 푈 푡 푈 푉 − 푒 ( + ) ℎ ( 푉 ) 퐶 The RC time constant =( ) gives time requiredstop 5 .to . charge푈 푡 the 푈capacitor− 푒 to approxi- 2 ( ± ) ( ) � ( ± ) ( () ( ) ) ( )( ) mately 63.2%= 1023 푢of the/5 charging voltage,푓 푥 orℎ to−= discharge 푓1023푥푢 − ℎ/5( the± capacitor) ( ) to approximately± ± ( ± ) ( ) ( ) . 휏푓 푥푅퐶≈ 푡 ≈( 휏) ( )( )( ±(. ) () ( )() .) (. ()) . 36.8% of (its initial) voltage.( ) As capacitor charging(/ ) and discharging are. asymptotic(± ± ±) pro(- )± ) ( ) � ± ( ) = (1 ℎ � ). ( �)( � ) ( ) . . . 푓 푥( )ℎ − 푓 푥 . � 푓 푥 ℎ −( 푓 )푓푥 푥푓 푥ℎ (−ℎ ) 푓−푥 푓 푥� . . cesses, the푎 time= to 0.5( 푢full ± charge) (is infinite.) An푎 approximate−푡=푅퐶 0.5푢푓 푥 stoppingℎ − 푓condition푥 is sometimes 푓 푥 ℎ − 푓 푥 푓 푥 ≈ ( ± ) ( ) 푓 푥 ≈ � 푓 �푓푥 � 푓≈푥 �푥≈푓 푥ℎ 푓−ℎ� 푓푥−푥 푓ℎ 푥−푓 푓푥푥 ≈ ( +� ) ℎ 푓((푥) ℎ) − 푓 푥 퐶 . 푓 푥 ≈ ( + ) ℎ ( ( +( 푓) +)푥ℎ) ℎℎ( −( 푓 )푥 ) ℎ (− 푓+푥 ) ( ) =established ( as) stop 5 . However,푈 . 푡 if 푈 the − capacitance 푒 ( and+ )푓 resistanceℎ 푥푓(≈푥 푓≈ in)푥 the≈ circuit are ℎ ( ) 푓 푥 ≈ � 1 . ( ± )1 ( )( ) ( )(푓 )( 푥+(≈+) .ℎ (푓) (ℎ+푥 ()≈ℎ) ((.) ) . ) . 2 ( � 푢+ =) 4.5푓 푥( ℎ −) 푓 푥 ( ) (푢 )= 4.5 2 . ( +2 )2ℎ ( + ) ℎ ( ) � unknown,푓 one푥 ≈ mustℎ푓 푥 useℎ a −different 푓 푥 stopping criterion,� based . (on2�) (available� )( )( ) numerical( ) data.. . . . 2 . 푓 푥( )ℎ −푓 푥푥 −≈ ℎ( + ) .( ) � 푓 푥 ℎ − 푓 푓푥 −푥푓 ℎ푥2ℎ −ℎ2 푓−푥 푓2 −푥� ℎ − ℎ 푓 푥 ℎ − 푓 푥 − ℎ 푓 푥 ≈ 휏 푅퐶 푡2( +≈ )휏ℎ ( � ) 푓 푥 ℎ푓−푥 푓푓≈푥푥 ℎ� 푓−�푓푥 푓 푥≈푥 −�≈ ℎ 2 ( ± ) 2 ( ) � ( /) 2 ℎ . 푓 푥2 ≈ � 푓 /푥푓 푥ℎ 푓−ℎ� 푓푥−푥 푓/ℎ −푥 ℎ−/푓 − 푓 ℎ푥푥≈ − ℎ / ( ) = (1 푓ℎ(푥)푢 )ℎ=. 102− 푓 푥 − ℎ 푓 푥. ≈ 푢 = 102( ) =푓 (푥1 ≈ℎ/( )(=))푓.= (푥1( ()1ℎ −ℎ 푓).푥 ) −. ℎ( )−= 푓 .푥 ( −1 ℎ ℎ ). 2 ( + ) (( ) = )(1 푓ℎ 푓푥 푥푓≈). ≈푥 ≈ 푓 푥/ ≈/ / 푓 푥 ≈ �−푡 푅퐶 푓 푥 /ℎ 2− 푓 푥 − ℎ ℎ ( )−푡(=)푅퐶=(1( ()1ℎ= ℎ−푡(1)푅퐶−푡. /푅퐶ℎ). ). / ( ) �= (1 ℎ ). ( ) . −푡 푅퐶 ( ) =� (1 (ℎ) = )(.1 ℎ ). −푡 푅퐶 퐶 5.2. Solution푓 푥 1≈ 푓 푥 ℎ − 푓 푥 − ℎ 1 퐶 퐶 퐶 푓 푥 ℎ 퐶− 푓 푥 = 5 . 푈 푡 푈 − 푒 = / = = 5 . 2 퐶 푈 푡 5 .푈5 . −푈 푒푈푡 푡 푈푓 푈푥−−푡 푒≈−푅퐶−푡 푒 −푡푅퐶 푅퐶−푡 푅퐶 −푡 푅퐶 stop 푓 푥푎(≈=) =921−푡( 1푅퐶 ℎ / � ) . stop 푎 푈 = stop푡 921 stop 푈 = − 푒퐶 퐶 퐶 stop 5 . 푈 푡 푈 − 푒 퐶 ( ) == (1 ℎ ) . stop 푓 5푥 . ℎ − 푓 푥 − ℎ 퐶 퐶( + ) ℎ ( ) = = = stop stop 5 . stop5 . 푈5 푈푡. 푈푡 푈푈푡 푈푡−푈 푒−푈푈 푒−푡 푒− 푒 푈 − 푒 = 5 . 푈 푡 푈 − 푒 −푡 푓푅퐶 푥 ≈= = / stop 5 . stop 5 (. ) . stop 퐶2 −푡 푅퐶 ( ) = (1 2ℎ ). ( ± ) 2( ) 휏 =푅퐶 5 =푡 1 ≈ 휏 = 1000If charging푈푎퐶 voltage푡 휏푈= U푅퐶 5−, resistance 푒 휏 =휏= 푅퐶푡R 5=1 and푅퐶 5≈ capacity휏 푎 =푡 1 =C푡 11000≈are 휏≈ 휏known,휏푅퐶 = the1000= 1000problem� 푡 ≈ is 휏easily = stop 5 . 푈 푡4휏( =푈푅퐶 5102−)푒 = 푡 1 ≈ 휏 =4 (1000102 )= 5 ( )= 1 푓 푥 ℎ −= 푓1000. 푥 − ℎ = stop 5 . ( ) = . 휏 =휏푅퐶 5휏 푅퐶 휏 푅퐶 ( 푅퐶 ) =푡 1−푡푡푅퐶≈푡 ≈휏푡 ≈ 휏. ≈휏 =휏1000 푓 푥 ≈ 휏 푅퐶 푡 ≈ 휏 solved in GeoGebra. First, the values퐶 = 5= 5 = 5 , 휏 = = 푅퐶 51= 1 = and 1 = 푡 1 = 1000= ≈ � 1000 = 휏 are 1000 defined = 1000 and / = 5 = 1 == 1000 273 5 . 푈 푡 푈 − 푒 273 푓( 푥) = ℎ(1− 푓 ℎ푥 ). 푈 푉 푅 휏 =푘훺푅퐶 5 퐶 =푡 1 ≈휇퐹(휏 ) is graphed.= 1000푎 푈−stopThe( )constant 푉 푈푅 is( 푈 calculated) ( 푉 푘훺 ) 푉 푅 and 푅퐶 푎 points 푘훺 − 푘훺 푈 =휇퐹((=),푉퐶( 0), 퐶0 ) 푓 and 푅 푥 휇퐹 = ≈ 휇퐹 (=푘훺,( 0=5) (,5 0), are 0)=퐶 (5 , 0) 휇퐹 휏 =푅퐶 5 =푡 1 ≈ 휏 푟 푎 = 1000푈 ( ) 푉 푅 = (푘훺, 0) 푟 푎 =퐶 (5 , 0) 휇퐹 ( + ) ℎ ( −푡 푅퐶) 푈 푈 푈푉 (푈푉) 푉 푅푉 푈푅 (푘훺푅) 푉푅푘훺푘훺 푘훺퐶=푅 (퐶,퐶 0푘훺) 퐶휇퐹=휇퐹(퐶휇퐹,퐶 0)휇퐹= (5 , 0)휇퐹 = (5 , 0) 푈 ( ) 푉 푅 = (푘훺, 0) 휏=placed퐶퐶(푅퐶5 , 0on) 휇퐹 the axis.푡 퐶 ≈Lines휏 perpendicular퐶 퐶 to = the axis 1 are 1 placed 5 at ( . ) and 2 푈 2푡 and 푈 their − 푒 . 푈= 5푡 퐶=푈 1 푡 1 푈휏=푈푡1000푡 2 휏 휏 푇 푇퐶 휏stop휏 1 푇 푇 휏 2휏 2 푈 푉 푅 푘훺intersections퐶 with푈 (푡 휇퐹) ( ) are휏 defined 푇 휏( as)A = and 3.푇161 B. It is now휏 easily 푈 (푡 observed)( ) / 휏 � = that0.푇 632 푓 휏(푥 ) =ℎ 3.−푇161 푓 푥 − 휏 ℎ ( )/ = 0.632 퐶 ( ) 1 = ( ,2 0) = (5 , 0푥) 푈퐶 푡 푈퐶휏푥푡 푇1 휏 휏 푇1 휏푇2 휏 푇2 휏 푈 (푡) 휏 푇 휏( ) = 3.푇161and the휏 ratio ( )/ = 0.632 equals 63.2%.휏 푅퐶 푡 ≈푓 휏푥 ≈ / 푈 ( ) 푉 푅 퐶= (푘훺퐶, 0) =퐶 (5퐶 , 0) 휇퐹 = 5 퐶=퐶 1 ( ) =퐶 1000(1 ℎ ). 퐶 푈퐶 푡 휏 푇1 휏 The푇2 value휏 푈 (5푡푈 ) 푡= 4.966 corresponds 푈 휏 = 5to the voltage 푈220 푈across푡 휏 푈the capacitor 10푈 휏 at the end 푈 휏 푈 퐶 ( ) 퐶 ( ) = 3.161 푦퐶 ( )/ = 0.632 푦 −푡 푅퐶 푈 푡 푈 휏 퐶 푈1 휏 푈 2 푈 푉 푅 푘훺 퐶 퐶 휇퐹 푈of( 푡charging.) 휏 The푇 slope휏( ) of the푇 graph휏 at that= point ( is) found stop by placing5 . the푈 tangent푡 푈 S to− 푒( ) 퐶 퐶 퐶 퐶= 3.161 / = 0.632 푈 (5푡 ) = 4.966 푈 휏 at = 5 . In the 푈 example 220휏 푈 휏 in 푈Fig. 푉 10 the10 slope푡 휏is 0.033. Different훺 values of R 푘훺yield differ- 퐶 퐶 퐶 퐶 푈 (푡 ) 푈 휏 휏 =푅퐶 5 푈 휏 푈 =푡 1 ≈ 휏 = 1000 푈 푡 퐶 ent5 values= 4. 966of the slope. For = example, 5 for 220 and 10 the slope is 0.153 and 0.003 푈 휏 푉 respectively.푡 휏 훺 푘훺 푈퐶 휏 푉 푡 휏 푈 푉 훺 푅 푘훺 푘훺 퐶 휇퐹 ( ± ) ( ) ( ) . ( ± ) ( ) ( ) � 푓 푥 ℎ.. − 푓 푥 푓 푥 ≈ �� 푓 푥 ℎ (− 푓+ 푥) ℎ ( ) 푓 푥 ≈ ( ) . ( + ) ℎ ( 2) ( ) � 푓 푥 ℎ −.. 푓 푥 − ℎ 푓 푥 ≈2 �� 푓 푥 ℎ( )−= 푓 푥(1 − ℎ ℎ / ). 푓 푥 ≈ ( ) ( / ) −푡 푅퐶 = 퐶1 ℎ .. = stop 5 . 푈 푡 −푡푈푅퐶 − 푒 퐶 = stop 5 .. 푈 푡 푈 − 푒 휏 =푅퐶 5 =푡 1 ≈ 휏 = 1000 휏 =푅퐶 5 =푡 1 ≈ 휏 = 1000 푈 ( ) 푉 푅 = (푘훺, 0) =퐶 (5 , 0) 휇퐹 푈 ( ) 푉 푅 = (푘훺,, 0 0) =퐶 (5 ,, 0 0) 휇퐹 퐶 1 Arduino and 2Numerical Mathematics 249 푈 (푡) 휏 푇 휏( ) = 3.푇161 휏 ( )/ = 0.632 퐶 1 2 푈 (푡) 휏 푇 휏( ) 푇 휏 ( ) 퐶 = 3.161퐶 / =퐶 0.632 If the 푈values(5푡 ) for=4. R966 and C 푈 are 휏 unknown = 5 or unreliable, 220푈 a휏 different 푈 criterion10 is devised 퐶 퐶 퐶 푈to (stop푡 ) charging. By푈 sampling휏 the voltage across푈 휏 the푈 capacitor during charging, an array 5 = 4.퐶966 = 5 220 10 of values (푈, )휏, = 1,2, …푉 is obtained. = 2,3,푡 … The 휏 slope of the훺 tangent to the charging푘훺 curve at 퐶 (푈,, )휏 ,,is observed= 1,2, …푉 for = 2,3,푡 … 휏 and charging is훺 stopped as soon푘훺 as it falls below a certain 푖 푢푖 푖 푖 threshold.푖푖 The slope is calculated numerically by using one of the difference schemes for푖 푢 the first푖 derivative.푖 The experiment was set up on a breadboard according to the schematic (Fig. 9). The voltage across the capacitor was measured with analog input pins on the Arduino. Power supply on the Arduino was used to charge the capacitor. The capacitor was discharged through a different resistor and a red LED.

Fig. 9. Setup for the capacitor charging experiment

Fig. 10. Solution of the charging problem in GeoGebra ( ± ) ( ) ( ) . ( , ), ( , ),…, ( , ), = 1,2, … � 푓 푥 ℎ − 푓 푥 ( ± ) ( ) 푓 푥 ≈ ( ) . ( + ) ℎ ( ) 푥( 0 푦0 ) (푥1 푦1 ) (푥푛 푦푛) 푛 ( ) . � ,푓 푥 , ℎ, − 푓,…,푥 , , ( ( ±=± 1,2,)) … (( )) 2 푓 푥 ≈ (( )) . . � 푓 푥 ℎ − 푓 푥 − ℎ 0( 0+ ) 1ℎ 1( )푛 푛 푓 푥 ≈ ( ) 푥 푦 푥 푦 =� �푥 1. 푦 푓푓푥푛푥 ℎℎ −− 푓 푓푥푥 ( ) = (1 ℎ / ). 2 푓푓 푥푥 ≈≈ � 푓 푥 ℎ − 푓 푥 − ℎ (( ++ ))ℎℎ (( )) −푡 푅퐶 퐶 푓 푥 ≈ / 푛(( )) ( )( . . ) 푈 푡 푈 − 푒 ( ) =( ) = (1 +ℎ ). = + 22 = . stop 5 . � � 푓푓푥푥 ℎℎ −− 푓 푓푥푥 − − ℎ ℎ 푥 − 푥1 −푡 푥푅퐶푓푓 −푥 푥0 ≈≈ 푥 − 푥0 푦1 − 푦0 1 퐶 0 1 (())==0 ((11 ℎ휏ℎ //푅퐶)).. 푡 ≈ 휏 = stop 5 퐿. 푥 푈 푦푡 0 푈 1− 푒푦 1 0 푦 1= 5 0 = 1 = 1000 푥 − 푥 푥 −0 푥 푥−푡−푡−푅퐶푅퐶 푥 푈푈퐶퐶 푡푡 푈푈 −− 푒 푒 휏 =푅퐶 5 =푡 1 ≈ = = 휏 = 1000 stopstop 55 . . 푈 ( ) 푉 푅 = (푘훺, 0) =퐶 (5 , 0) 휇퐹 푉 휏휏 푅퐶푅퐶 푡푡 ≈≈ 휏휏 퐶 1 2 푈 ( ) 푉 푅 = (푘훺, 0) = = 5 5 = 퐶 ( 5 , 0)= = 휇퐹 1 1 ==10001000 푈 (푡) 휏 푇 휏( ) = 3.푇161 휏 ( )/ = 0.632 = 1023푢 /5 퐶 1 2 퐶 퐶 퐶 푈 (푡) 휏 푇 휏( )푈푈=(( 3.))푇 161푉 푉 휏 푅 푅 = = ( ( 푘훺 푘훺,, 0 0)() ) / ==퐶=퐶 0.((56325 ,, 0 0 )) 휇퐹 휇퐹 푈 (5푡 ) = 4.966 푈 휏 = 5 220푈 휏 푈 10 푎 = 0.5푢 퐶 250 퐶 푈푈퐶퐶 푡푡 휏휏 푇푇11 휏휏Đ.퐶 Herceg,푇푇22 D. Herceg휏휏 푈퐶 휏 푉 푡 휏 훺 푘훺 푈 (5푡 ) = 4.966 푈 휏 (()=) 5 220((푈))= 휏= 3. 3. 푈161 161 1 10 ((())/,/ )==, 0. 0.632=632 1,2, … = 2,3, … 푢 = 4.5 퐶 푈푈퐶퐶 푡푡 푈푈퐶퐶 휏휏 푈푈퐶퐶 휏휏푖 푈푢푈푖 푖 푖 (푈, )휏, = 1,2,The …푉 experiment= 2,3,(푡(55 ) …was)=휏= 4. 4.conducted966966 several 훺 == 5times,2 5 with 푘훺 220 220 , 1000 and 10 =1010 resistors× 1 = 10 1/5 푢 used for charging. For brevity, only the= 102 last case is described. In this case 푖 푈푈퐶퐶 휏휏 푉푉 푡푡 휏휏 훺훺 훺 휏 푘훺푘훺푘훺 푚퐹 푠 1000푖 푢 푖 = 10 ×푖 1 = 10 . Voltage 1/5 data was1 sampled in 1/5s intervals and saved into a 푎 = 921 file. The data was read into Mathematica, the values were scaled to the correct voltage 훺 휏 푘훺 푚퐹 푠 2 range using linear interpolation and graphed푎 4 (Fig.( 11).102) ( ) = . The symmetric difference formula was used to273 calculate numerical approximations to the first derivative at each sampled point except 푎the − first and last, and the resulting data was 푟 푎 graphed (Fig. 12). Also, sample indices on the axis were converted to time in seconds. The graph in Fig. 12 is jagged due to electronic noise, low precision of the A/D con- version and possibly other artifacts. It is obvious푥 that the slope of the tangent decreases with time, however, choosing a simple threshold for the slope would probably not be the 푦 best stopping criterion, because a spike due to noise might trigger the criterion too early. A better solution would be to use moving average with appropriate window size or to numerically smooth the sampled curve.

Fig. 11. Voltage across the capacitor while charging.

Fig. 12. Result of numerical differentiation. Arduino and Numerical Mathematics 251

Fig. 13. The filtered curve.

5.3. Curve Smoothing

As discussed in the previous section, the curve obtained by numerical differentiation (Fig. 12) should be smoothed before the stopping criterion is applied. If the analytical form of the curve is known, then an appropriate linear or nonlinear fitting procedure can be applied to fit it to experimental data. If the analytical form is not known, filtering is often applied to remove noise and obtain a smooth curve. We chose to apply the Gauss- ian filter. The GaussianFilter function already exists in Mathematica and is not difficult to program in C#. The curve obtained by filtering is shown in Fig. 13. With noise removed from the data, the curve is now smooth and the stopping crite- rion can be applied more reliably.

6. Classroom Experiences

The focus of our research was to determine whether the exercises described in this pa- per help promote student motivation, skills development and knowledge retention. The exercises were introduced into the Numerical mathematics course held at the Faculty of Science, University of Novi Sad, during the school years of 2018/2019 and 2019/2020. We conducted an experiment, described in detail in Section 7, which confirmed our expectations. The exercises were also used as motivational examples in our other courses: a C# programming course and an Arduino programming course held for students at the Fac- ulty of Science, and also in three courses on Arduino programing, which we held for el- 252 Đ. Herceg, D. Herceg ementary school and high school teachers during 2018. In these cases, no formal testing was conducted. Instead, we held informal conversations with the students throughout the courses, and the teachers were given a questionnaire, in order to collect their opinions and insights. The feedback from all participants was generally positive, with the majority agreeing that they liked the practical and tangible approach to the subject matter, as well as horizontal curriculum integration. We present some of the most interesting remarks and comments, which will help us improve our approach to teaching in the future. “It is frustrating when a program sometimes writes floating‑point numbers with a decimal point and sometimes with a comma.” Upon being explained why this hap- pens, namely, that the decimal separator depends on regional settings of the operating system, the students concluded that “a scientist needs not know such intricate details outside their domain of interest”. In their view, having to write extra code to solve some- thing that should not be a problem in the first place is “extraneous”. This is one example where the flexibility of the software platform, i.e. support for various languages and cultures, effectively becomes an obstacle to the programmer. “Integer division is causing numerical errors” While mapping the values read from Arduino to voltages, most of the students encountered numerical errors stemming from integer division. The students previously took a C# programming course which covered integer and floating-point data types, as well as the differences between integer and float- ing-point division. Despite that, they were expecting the division to work in the same way as in Mathematica, unaware of the implications of using only integer values in C# expressions. This error was easily remedied by casting integers to a floating-point data type. Obviously, theoretical knowledge from previous courses does not always transition to practical knowledge and some repetition is necessary. “I don’t like having to dimension the arrays beforehand.” This statement pertains to the creation of arrays in C#. The programmer can choose between fixed-length ar- rays and variable-length lists. The arrays provide the fastest element access but must be defined beforehand, while lists can expand as new elements are added, but element access is somewhat slower. We explained the differences between arrays and lists to the students and suggested them to use arrays when execution speed is the primary goal. The lists should be used when the number of elements is not known beforehand, or during development, when flexibility is more important. Even after being explained this, some students maintained that gains in computational speed may not be worth the confusion that stems from two different implementations of arrays in C#. One interesting consequence of using both lists and arrays is that the number of ele- ments in an array is kept in its Length property, while lists use the Count property for the same purpose. This has led to some confusion among the students, who noticed that Mathematica “does it right” by providing a simple Length function. “Why isn’t there scalar product in C#” pertains to C# that the students wrote to calcu- late convolution necessary for the Gaussian filter. The students preferred having vector and matrix operations already implemented in the language or in libraries, instead of having to write the code by themselves. After we explained that there were, in fact, many available software libraries, the students wanted to know why we avoided using them. Arduino and Numerical Mathematics 253

This led to a lengthy discussion about the issues which may arise by including third- party code into one’s own project: Is the said code reliable? Can it be easily checked and verified for correctness? Does it carry too much unnecessary weight or further de- pendencies? In the end, we concluded that, for the purpose of this task, it was easier to write our own code. Finally, we asked the students to ponder the following points and then form their opinion on the usefulness of C# in solving the presented problems: ●● Can you write the solution in C# right away? ●● Is it easier to solve one problem in Mathematica? ●● If you had to solve many problems, or problems with large amounts of data, would you then consider solutions in C# to be the most practical? The consensus among the students was that, for research, everyday work and study, scientific software such as Mathematica and GeoGebra is more suitable than a general- purpose . If we shift our focus to high-performance computing and processing of large amounts of data, the balance shifts in favor of languages such as C# and C++.

7. The Experiment

An experiment was carried out in order to determine whether our examples promote stu- dent motivation, skills development and knowledge retention. We observed 33 students in two parallel groups. There were 16 students in the control group (C) and 17 in the experimental group (E). The control group was instructed in a classical way, with two hours of lecture for each topic, followed by two hours of exercises. Theoretical lessons on interpolation, numerical integration and numerical differentiation were presented in lectures, followed by practice sessions in which the students solved computational prob- lems on paper with the help of Mathematica. Data for the problems was arbitrarily gen- erated, without connection to the real world. Lectures for the experimental group were organized around the examples presented in this paper in the same time frame as for the control group. Lectures started with a theoretical introduction followed by demonstra- tions by the lecturer and hands-on exercises. During practice sessions the students were assigned problems similar to those presented in the exercises described in the paper. Exercises were conducted in a computer lab and data for the experiments was acquired from measurements using Arduino hardware. Problems were solved on computers, using Mathematica, Arduino and C# IDEs.

7.1. Initial Testing

To establish a baseline, a test was given to both groups immediately before the experi- ment. The students solved computational problems in the classical way, earning a maxi- mum of 100 points. During the test, some students did not complete all the assignments ( ± ) ( ) ( ) . � 푓 푥 ℎ − 푓 푥 푓 푥 ≈ ( + ) ℎ ( ) ( ) . 2 � 푓 푥 ℎ − 푓 푥 − ℎ 푓 푥 ≈ ( ) = (1 ℎ / ). −푡 푅퐶 퐶 = stop 5 . 푈 푡 푈 − 푒

휏 =푅퐶 5 =푡 1 ≈ 휏 = 1000 ( ± ) ( ) ( ) . � 푓 푥 ℎ − 푓 푥 푈 ( ) 푉 푅 = (푘훺, 0) =퐶 (5 , 0) 휇퐹 푓 푥 ≈ ( + ) ℎ ( ) 퐶 1 2 ( ) . 푈 (푡) 휏 푇 휏( ) = 3.푇161 휏 ( )/ = 0.6322 � 푓 푥 ℎ − 푓 푥 − ℎ 퐶 퐶 푓 푥퐶 ≈ / 푈 (5푡 ) = 4.966 푈 휏 = 5 220푈 ( 휏 ) = 푈 ( 1 10ℎ ). −푡 푅퐶 퐶 푈퐶 푡 푈 − 푒 254(푈, )휏, = 1,2,= …푉 = 2,3, 푡 … stop휏 Đ. Herceg,5 . D.훺 Herceg 푘훺 푖 휏 푅퐶 푡 ≈ 휏 and1000푖 푢 gave 푖 up = just10= as 5 they × 푖 1 scored ==10 1enough p points =for1000 the passing grade. Comparing the re- sults using the t-test, we confirmed that there was no statistically significant difference ( = 0.훺93 with 휏 푈 the( 푘훺 ) 푉 95% confidence푚퐹 푅 = (푘훺푠, 0 )level) in=퐶 test(5 ,scores 0) 휇퐹 between the groups (Table 1).

퐶 1 2 푝 푈푝 (푡) 휏 푇 휏( ) = 3.푇161 휏 ( )/ = 0.632 7.2. Final Testing 퐶 퐶 퐶 푈 (5푡 ) = 4.966 푈 휏 = 5 220푈 휏 푈 10

퐶 The second test(푈, was)휏, given= 1,2, at …푉 the end = of 2,3,푡 the … 휏 experiment. Both훺 groups did the푘훺 test on pa- per with the help of Mathematica. During the test it was obvious that the experimental 푖 group was more1000푖 푢 determined 푖 = 10 to complete×푖 1 = their10 assignments. p Comparing the results for the control and experimental groups, the null hypothesis can be rejected with the 95% confidence level,= 0.훺 93since 휏 = 0.푘훺043 <푚퐹 0.05 (Fig. 푠 2). It can be concluded that there is a statistically significant difference in test scores푝 between the groups. The results푝 of the experiment푝 highlight the better results of the experimental group in mastering the presented learning topics. We noticed that the motivation was higher in the experimental group, which can be attributed to the more engaging and tangible approach to the subject matter, the use of interesting new technologies and dealing with real-world experimental data.

8. Conclusions

Interpolation, numerical integration and numerical differentiation are important topics in Numerical Mathematics, which are often taught only theoretically and demonstrated using some arbitrary data. By employing inexpensive Arduino hardware and mathemat- ics software such as GeoGebra and Mathematica, a teacher can help students establish a connection between real world problems and mathematics and motivate them with inter- esting examples in which discovery plays a significant role. Imperfections and inaccura-

Table 1 Baseline test scores

Group No. of students Average points Std. deviation t p

C 16 61.25 23.95 0.08 0.93 E 17 60.59 21.82

Table 2 Test scores after the experiment

Group No. of students Average points Std. deviation t p

C 16 68.75 22.61 -2.11 0.043 E 17 83.52 15.31 Arduino and Numerical Mathematics 255 cies which occur in experiments also stress the difference between theory and practice and highlight the need for a pragmatic way of solving problems. The same applies to the choice of the software for solving problems, as both the specialized scientific software and the general programming languages have their advantages and disadvantages. Obvi- ously, one must decide the priorities. Do we aim for mathematical clarity or speed of computation? Are we willing to sacrifice the simplicity of specialized scientific software for the versatility of a general programming language? The answer to these and similar questions is not simple, and it depends on stated aims and goals. A significant advantage of the Arduino platform is its low cost, ubiquity and avail- ability of software. Having in mind the positive feedback given by the participants of our classes, as well as the results of the experiment, we are planning towards developing more exercises based on Arduino and integrating them into the curriculum.

Acknowledgments

This paper has been supported by the Ministry of Sciences and Technological Develop- ment of the Republic Serbia, under the grant for project TR 32019. The authors thank the anonymous reviewers for their insightful suggestions, which helped improve the quality of the paper.

References

Bhagat, K.K., Chang, C. (2015). Incorporating GeoGebra into Geometry Learning A lesson from India, Eur- asia Journal of Mathematics, Science Technology Education 11.1, 77–86. Blum, W., Niss, M. (1991). Applied mathematical problem solving, modeling, applications, and links to other subjects – state, trends and issues in mathematics instruction. Educational Studies in Mathematics, Kluwer Academic Publishers, Dordrecht 22, 37–68. Blum, W., Borromeo Ferri, R. (2009). Mathematical Modelling: Can It Be Taught And Learnt? Journal of Mathematical Modelling and Application, 1.1, 45–58. Burkhardt, H. (2018). Towards Research-based Education. Shell Centre for Mathematical Education Publica- tions Ltd. 1–25. https://www.mathshell.com/papers/pdf/hb_2018_research_based_education.pdf. Cheng, H., Hao, L., Luo, Z., Wang, F. (2016). Establishing the Connection between Control Theory Education and Application: An Arduino Based Rapid Control Prototyping Approach. International Journal of Learn- ing and Teaching 2(1),67–72. DeJarnette, N. (2012). America’s children: Providing early exposure to STEM (science, technology, engineer- ing and math) initiatives. Education 133.1, pp. 77–84. DOI: 10.1007/s10649-005-9002-4 Drijvers, P. et al. (2016). Uses of Technology in Lower Secondary Mathematics Education. In: Uses of Tech- nology in Lower Secondary Mathematics Education. ICME-13 Topical Surveys. Springer, Cham, 1–34. DOI: 10.1007/978-3-319-33666-4_1 Gonzalez, H.B., Kuenzi, J.J. (2012). Science, technology, engineering, and mathematics (STEM) education: A primer, https://fas.org/sgp/crs/misc/R42642.pdf Han, O.B. et al. (2013). Computer Based Courseware in Learning Mathematics: Potentials and Constrains. Procedia – Social and Behavioral Sciences 103, 238–244. DOI: 10.1016/j.sbspro.2013.10.331. Herceg, D., Herceg, Đ. (2008). Numerical mathematics with GeoGebra in high school, Teaching Mathematics and Computer Science, 6/2, 363–378. Herceg, Đ., Herceg, D. (2009). Definite integral and computer, The Teaching of Mathematics, 12(1) 33–44. Herceg, Đ., Herceg, D. (2010). Numerical Integration with GeoGebra in High School, The International Jour- nal for Technology in Mathematics Education – 17(4), 205–210. 256 Đ. Herceg, D. Herceg

Hohenwarter, M., Hohenwarter, J., Kreis, Y., Lavicza, Z. (2008). Teaching and learning calculus with free dynamic mathematics Software GeoGebra, Proceedings of International Conference in Mathematics Edu- cation, Monterrey, Mexico Jezdimirović, J. (2014). Computer Based Support for Mathematics Education in Serbia. International Journal of Technology and Inclusive Education 3.1, 277–285. DOI: 10.20533/ijtie.2047.0533.2014.0036. Kaufmann, H., Schmalstieg, D. (2002). Mathematics and Geometry Education with Collaborative Augmented Reality. ACM SIGGRAPH 2002 Conference Abstracts and Applications. SIGGRAPH ’02. San Antonio, Texas: ACM, pp. 37–41. DOI: 10.1145/1242073.1242086. Kim, E., Shin, K.G., Lee, J. (2014). Real-Time Discharge/Charge Rate Management for Hybrid Energy Stor- age in Electric Vehicles, 2014 IEEE Real-Time Systems Symposium, DOI: 10.1109/RTSS.2014.16 Lavicza, Z. (2007). Factors influencing the integration of Computer Algebra Systems into university-level mathematics education. International Journal for Technology in Mathematics Education 14(3), 121–129. Lavicza, Z et al. (2018). Educational experience in teaching mathematics online: a case study on the imple- mentation of GeoGebra in an interactive learning environment. INTED 2017, 11th annual International Technology, Education and Development Conference, 110–122. Mainali, B.R., Key, M.B. (2012). Using dynamic geometry software GeoGebra in developing countries: A case study of impressions of mathematics teachers in Nepal. International Journal for Mathematics Teaching and Learning, 1–16. http://www.cimt.org.uk/journal/mainali.pdf Niss, M. (2012). Models and Modeling in Mathematics Education. EMS Newsletter December 2012, 49–52. http ://www.euro-math-soc.eu/ems_education/Solid_Findings_Modelling.pdf Prensky, M. (2008). The Role of Technology in Teaching and the Classroom, Educational Technology Nov– Dec 2008. Sathik, M.H., Prasanth, S., Sasongko, F., Poub, J. (2018). Online condition monitoring of IGBT mod- ules using voltage change rate identification, Microelectronics Reliability 88–90, 486–492, DOI: 10.1016/j.microrel.2018.07.040 Tomaschko, M., Hohenwarter, M. (2017). Integrating mobile and sensory technologies in mathematics educa- tion. Proceedings of the 15th International Conference on Advances in & Multimedia, 39–48. Underkoffler, M.M. (1969). Computer assisted instruction in college general education mathematics. PhD thesis. Iowa State University, DOI: 10.31274/rtd-180813-1201 Zbiek, R.M., Conner, A. (2006). Beyond Motivation: Exploring Mathematical Modeling as a Context for Deepening Students’ Understandings of Curricular Mathematics. Educ Stud Math 63.1, 89–112. DOI: 10.1007/s10649-005-9002-4

Đ. Herceg is a Full Professor at the Department of Mathematics and Informatics, Faculty of Science, University of Novi Sad. His research is focused on Numerical mathematics and the use of computers in teaching. D Herceg is an Assistant Professor at the Faculty of Technical Sciences, University of Novi Sad. Her research is focused on the modeling and measurement of electromagnetic fields, as well as the use of boards in teaching.