0% found this document useful (0 votes)
72 views18 pages

Arduino and Numerical Mathematics

Uploaded by

Lavabo At Lavabo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views18 pages

Arduino and Numerical Mathematics

Uploaded by

Lavabo At Lavabo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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


1
Department of Mathematics and Informaics, Faculty of Science, University of Novi Sad
Novi Sad, Serbia
2
Department of Power, Electronic and Telecommunication Engineering
Faculty of Technical Sciences, 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, C++ and C# development envi-
ronments. This work is a continuation of our previous work on teaching of Numerical
mathematics using computers (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 computer software (Mathematica and/or GeoGebra) mainly as a
programmable calculator.
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).
(𝑥1 , 𝑦1 ),We
… ,chose
(𝑥𝑛 , 𝑦Arduino hardware because it is easy to obtain at a modest price,
𝑛 ), 𝑛 = 1,2, …
ubiquitous, well supported and easy to configure for the presented teaching topics.
𝑛 𝑛
�𝑥 − 𝑥� �
𝐿𝑛 (𝑥) = � 𝑦� � .
3. Interpolation �=�
�𝑥� − 𝑥� �
�=�
���

3.1. Definition
(𝑥� , 𝑦� ), (𝑥1 , 𝑦1𝑛), … , 𝑛(𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, …
We 𝐿start by introducing �𝑥 − the 𝑥� � Lagrange polynomial. For a given set of data points
𝑛 (𝑥) = � 𝑦� � .
(𝑥� , 𝑦� ), (𝑥1 , 𝑦�=� , (𝑥𝑛 , 𝑦�𝑛 ), 𝑥�𝑛� = 1,2, … the Lagrange polynomial is defined as
1 ), … �=�
�𝑥 −
���

𝑛 𝑛
�𝑥 − 𝑥� �
𝐿𝑛 (𝑥) = � (𝑥
𝑦� ��, 𝑦� ), (𝑥1 , 𝑦1.), … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, …
�=�
�𝑥� − 𝑥� �
�=�
(𝑥���
� , 𝑦� ), (𝑥1 , 𝑦1 ), … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, …

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
(𝑥0 , 𝑦0 ), (𝑥1heaters
, 𝑦1 ), … ,and(𝑥𝑛 ,washing
𝑦𝑛 ), 𝑛 = 1,2, … To measure water pressure one can use mechanical or
machines.
(𝑥 , 𝑦 ), (𝑥1 , 𝑦1 ), … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, …
electronic devices. An electronic water pressure sensor can simply0 be0 installed in a water
(𝑥0 , 𝑦0 ), (𝑥1 , 𝑦1 ), … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, …
pipe and connected to, 𝑦Arduino (Fig.
), … ,1).(𝑥𝑛The, 𝑦𝑛 ),sensor produces output from 0.5 to 4.5V,
(𝑥0 , 𝑦0 ), (𝑥1 , 𝑦1 ), … , (𝑥𝑛 , (𝑥 𝑦𝑛0), 0𝑛),=(𝑥1,2, 1 , 𝑦1… 𝑛 = 1,2, … (𝑥0 , 𝑦0 ), (𝑥1 , 𝑦1 ), … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, …
corresponding to pressures from 0 bar to 12 bar. The dependency is linear.
𝑛=1
To0measure
(𝑥0 , 𝑦0 ), (𝑥(𝑥 , 𝑦0 ), water ), …pressure, we
𝑦…1 ),𝑛need to write a C++ program to read the voltage 𝑛 =from
1 𝑦1 ),
, …(𝑥 1 ,𝑛𝑦
, (𝑥 1(𝑥
,𝑦 , 𝑦, (𝑥 , 𝑦1𝑛, ),
), (𝑥
𝑛 ),0 𝑛0=𝑛1,2,
…=, (𝑥1,2,
𝑛 , 𝑦…
𝑛 ), 𝑛 = 1,2, … 1
𝑥 − 𝑥1 the sensor 𝑥 − 𝑥0and convert (𝑥 −it𝑥to 0 )(𝑦pressure.
1 − 𝑦 0 ) The result is displayed on a 7-segment display or
(𝑥) = 𝑦0 +otherwise
𝑦1 (𝑥 , 𝑦 relayed
),=(𝑥𝑦0, 𝑦+to), the
… , user.
(𝑥 , 𝑦 ), 𝑛 =
𝑛 .=
1,2,
1 … 𝑥 − 𝑥 𝑥 − 𝑥 (𝑥 − 𝑥0 )(
𝑥0 − 𝑥1 𝑥1 −0 𝑥00𝑛 = 11 1 𝑥1𝑛− 𝑛𝑥0 1 0
𝐿1 (𝑥) = 𝑦0 + 𝑦1 = 𝑦0 +
𝑥0 − 𝑥1 𝑥1 − 𝑥0 𝑥1 −
𝑥 − 𝑥1 0𝑉 𝑥 − 𝑥 𝑥
𝑛 −=(𝑥𝑥11− 𝑥 )(𝑦 𝑥 −
− 𝑥𝑦0 ) (𝑥 − 𝑥0 )(𝑦1 − 𝑦 0 )
𝑦1 𝐿1 (𝑥) ==𝑦𝑦00𝑥+− 𝑥 + 𝑦1 𝑥 − 𝑥 =
0 0 1 0
𝐿1 (𝑥) = 𝑦0 3.3. +Solution . 𝑦0 + 𝑥1 − 𝑥0
.
0𝑉
𝑥0 − 𝑥1 𝑥1 − 𝑥0 0 1 𝑥1 − 𝑥 10 0
𝑥𝑢− 𝑥1 𝑥 − 𝑥0 (𝑥 − 𝑥0 )(𝑦1 − 𝑦0 )
𝐿1 (𝑥) = 𝑦0 + 𝑦1 = 𝑦0 + .
First, a𝑥formula
0−𝑥 0𝑉1 to 𝑥convert
1 − 𝑥0 the voltage 0𝑉 𝑥from
1 − 𝑥the0 sensor’s output pin to pressure𝑢must
be𝑎constructed.
= 1023𝑢/5 Arduino has analog input pins 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-
𝑢1 = 0.5
sor output’s range, integer values which correspond to input values of 0.50𝑉 and 4.50𝑉
𝑎 = 1023𝑢/5 𝑢 𝑎 = 1023𝑢/5 𝑢1 = 0.5
are determined.
𝑢2 = 4.5
Interpolating polynomial is constructed for points (0,0), (5,1023),
which yields a ratio between the input voltage on the sensor 𝑢 and analog𝑢2reading
𝑢1 = 0.5𝑎 = 1023𝑢/5 𝑢1 = 0.5 = 4.5
𝑎=𝑎 1023𝑢/5
1 = 102 .
By substituting
𝑢2 = 4.5 𝑢1 = 0.5 0.5 and 𝑢2 = 4.5 4.5 and rounding the results, we get 𝑎1 = 102 102
and 𝑎2 = 921 . These are the readings Arduino will get when sensor voltages are 0.50𝑉
and 4.50𝑉𝑎respectively.
1 = 102
𝑢2 = The 4.5readings 𝑎1 = are102converted to pressure by constructing 𝑎2another
= 921
interpolating polynomial for points (102,0), (921,12):
𝑎2 = 921 𝑎1 = 102 𝑎2 = 921

𝑎2 = 921
4(𝑎 − 102)
𝑟(𝑎) = .
273
𝑢2 = 4.5 𝑢1 = 0.5
𝑢1 = 0.5
𝑎1 = 102 𝑢2 = 4.5
𝑢2 = 4.5
Arduino and
𝑎 =Numerical
921 Mathematics 243
2 𝑎1 = 102
𝑎1 = 102
4(𝑎 − 102)
The resulting polynomial 𝑟(𝑎) = converts readings
. from the analog 𝑎input
2 = 921
pin on the
273 𝑎2 = 921
Arduino to pressure in the range from 0 bar to 12 bar. The calculation can be executed
4(𝑎 − 102)
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 𝑢1 = 0.5 𝑥𝑥 𝑦 4(𝑎 − 102)
𝑦
𝑢2 = 4.5 𝑎1 = 102 𝑟(𝑎)
𝑦 = .
𝑢2 = 4.5 𝑢 = 4.5 𝑛 273
𝑛 2 𝑦 𝑦

𝑎2 = 921𝐴 = � 𝑓(𝑥𝑖 )∆𝑥𝑖
𝑛 𝑛
𝑎1 𝐴 == 102� 𝑓(𝑥 ∗
)∆𝑥 𝑥
𝑎1 = 102 𝑎 = 102
𝑖 𝑖 𝑛 𝑛 𝐴 = � 𝑓(𝑥 ∗
)∆𝑥 𝐴 = �
244 𝑖=1 1 ∗ ∗
Đ. Herceg, D. Herceg
𝑖=1 𝑖 𝑖

𝑎2 = 921 𝐴𝐴 == �� 𝑓(𝑥
4(𝑎 � )∆𝑥
𝑓(𝑥
− )∆𝑥
𝑖102)� 𝑖 𝑖=1
𝑦 𝑖=1
𝑎2 = 921 ∗ [𝑥 ].
4.𝑥Numerical ∗ 𝑟(𝑎)
Integration
𝑎2𝑖−1 =
= ,921
�=1 ∆𝑥 𝑖 = 𝑥 𝑖 − 𝑥 .
𝑖−1 , 𝑥 𝑖 ∈ 𝑖−1 , 𝑥 𝑖
∆𝑥𝑖 = 𝑖 − 𝑥𝑖−1 , 𝑥𝑖 ∈ [𝑥 𝑥𝑖 ]. 273
𝑖=1
4(𝑎 − 102) ∆𝑥𝑖 = 𝑥𝑖 − 𝑥𝑖−1 , 𝑥𝑖∗ 𝑛∈ [𝑥𝑖−1 , 𝑥𝑖 ]. ∆𝑥𝑖 = 𝑥𝑖 − 𝑥𝑖−1
𝑟(𝑎) = 4(𝑎
∆𝑥 ∆𝑥 −
. = 102)
=𝑥
� 𝑖 � 𝑖4(𝑎 −
𝑥 𝑥
− 𝑥 , ,𝑥 ∗
𝑥 ∈∗ [𝑥
∈ 𝑥
[𝑥∗
,
= 𝑥 ,𝑥].
𝑥 ]. ,
. �−1− 𝑥102) ∗
𝑟(𝑎)273 ∗
𝑖 = 𝑥𝑖−1
𝑥= , 𝑖−1 � 𝑖 �−1
𝑖 𝑖−1 � 𝑖−1 𝑖 𝐴 = � 𝑓(𝑥� )∆𝑥�
4.1. Definition 𝑟(𝑎)
273 = . 𝑥𝑖∗ = 𝑥𝑖−1 , 𝑥𝑖∗ =
∗ ∗273 ∗ �=1
𝑥 𝑥𝑖∗ = 𝑥𝑖 𝑥� 𝑥= 𝑖 = 𝑥
𝑦�−1 𝑥𝑖−1, , 𝑥𝑖 = 𝑥𝑖
𝑥
The concept of definite𝑥 integral is introduced as ∆𝑥 the� = 𝑥𝑖∗𝑥=−𝑥𝑥𝑖 of, area
problem under
𝑥�∗ ∈ [𝑥�−1a, 𝑥graph. The 𝑥𝑖∗
� �−1 � ].
∗ ∗ 𝑥 + 𝑥
Riemann𝑦 𝑥sum
𝑖 +𝑥 is𝑖−1 defined𝑥�𝑛as 𝑥= 𝑖 = 𝑥� 𝑥𝑖 ∗
𝑥 =
𝑖 𝑖−1
. 𝑥𝑖 + 𝑥∗𝑖−1 𝑥𝑖
𝑥𝑖∗ = 𝑦 . 𝐴 =𝑦 � 𝑓(𝑥 ∗ )∆𝑥𝑖 � 2 𝑥� =. 𝑥�−1 ,
2 𝑥 + 𝑥
� 𝑥𝑖∗ = 𝑥𝑖∗ =
𝑛 ∗ �=1 𝑖 � 𝑥 + 𝑥
�−1 𝑖−1 2
𝑛 𝑥�∗𝑥= = ∗. .
𝐴=� 𝑥𝑖∗𝐴𝑓(𝑥
==(𝑥

� )∆𝑥+ �𝑥 ∗ )/2.
𝑛 𝑖 2 2𝑥𝑖 = (𝑥𝑖 + 𝑥𝑖−1 )/2. 𝑥∗ = 𝑥
𝑖−1)∆𝑥
� 𝑖 𝑓(𝑥
∆𝑥 𝐴 �= = 𝑥 � � −𝑓(𝑥𝑥 ∗ , 𝑥 ∗ ∈ [𝑥
)∆𝑥 , 𝑥 ]. 𝑥𝑖∗ = (𝑥𝑖 + 𝑥𝑖−1�)/2. � 𝑥𝑖∗ = (𝑥𝑖
�=1
𝑥𝑖 +𝑥𝑖−1 � ∗� ∗ �−1 � � �−1 �

𝑥𝑖 = .�=1 𝑥 = (𝑥
� 𝑥𝑖 = (𝑥 +
� 𝑖 +�−1 𝑥 )/2.
𝑥𝑖−1 )/2. 𝑥� 𝑥++𝑥𝑥�−1
2 𝑥𝑖�=1
𝑥 ∗
=
+𝑥𝑖−1
∗. 𝑥�∗𝑥=

= 𝑖 𝑖−1 .
22 .
∗ [𝑥 ].
∆𝑥 � = 𝑥 � − 𝑥 �−1 , 𝑥� ∈ 𝑖
�−1 � 2, 𝑥 𝑥 � = 𝑥 �−1 , 𝑖
∗ ∗ 𝑥� +𝑥
𝑥𝑖 +𝑥
𝑥� 𝑥= �−1𝑖−1
𝑖 = 2 2. . where ∆𝑥� = 𝑥� − 𝑥�−1 , 𝑥� ∈ [𝑥�−1 , 𝑥ℎ� ].=Several ∗
∆𝑥𝑖 special cases are observed, left rule for
𝑥�∗ = 𝑥�−1 ℎ ,=right
∆𝑥𝑖 rule for 𝑥 ∗ = 𝑥 and midpoint rule, forℎ 𝑥=�∗ ∆𝑥
� � = 𝑖(𝑥� + 𝑥�−1 )/2. In the case of ℎ=
equidistant points, i.e. ℎ = ℎ= ∆𝑥∆𝑥 � for
𝑖 𝑖 = 1,2, … , 𝑛 , the formula becomes
𝑖 = 1,2, … , 𝑛 𝑥 +𝑥
𝑥�∗ = � �−1 . 𝑖 = 1,2, … , 𝑛 𝑖 = 1,
2
𝑛 𝑖 = 1,2, … , 𝑛
𝑛
𝐴 = ℎ � 𝑓(𝑥𝑖∗ ). 𝑛 𝐴 = ℎ � 𝑓(𝑥𝑖∗ ). 𝐴 = ℎ�
𝑖=1 ∗
𝐴 = ℎ � 𝑓(𝑥𝑖 ). 𝑖=1 𝑖=
𝑖=1
If the function f is unknown and only the points (𝑥𝑖 , 𝑦𝑖(𝑥 ) are available, 𝑓(𝑥𝑖∗ ) can be
𝑖 , 𝑦𝑖 )
(𝑥𝑖 , 𝑦𝑖 ) substituted

𝑓(𝑥𝑖 ) with (𝑦𝑖 + 𝑦𝑖−1 )/2 and thus the trapezoidal rule is obtained. Depending on the
course level, Newton-Cotes quadrature formulas may also be used.

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


𝑖 2 𝑖 𝑖 2 2
𝑥𝑥𝑖 +𝑥
𝑖 +𝑥𝑖−1
𝑥𝑖 +𝑥𝑥∗𝑖−1 𝑥𝑥𝑖∗𝑖∗ =
= ..𝑖−1
ℎ =ℎ ∆𝑥
= 𝑖∆𝑥𝑖
𝑥𝑖 𝑥=𝑖 + 𝑥𝑖−1𝑖 = .(𝑥𝑖
∗ + 𝑥𝑖−1 )/2. 22 𝑛 𝑛
𝑥𝑖∗ = 2. ℎ = ∆𝑥𝑖 ℎ =ℎ ∆𝑥 = 𝑖∆𝑥𝑖
2 𝐴 = ℎℎℎ = � 𝑓(𝑥𝑖∗ ). 𝐴 = ℎ � 𝑓(𝑥 𝐴=
𝑥 +𝑥
= 𝑖 𝑖−1 . 𝑖 =𝑖 1,2, … ,…
= 1,2, 𝑛 ,𝑛 = ∆𝑥
∆𝑥 𝑖 𝑖

2 𝑥 = (𝑥 + 𝑥 )/2. 𝑖 = Mathematics
1,2, … , 𝑛 𝑖=1 𝑖 =𝑖 1,2, …,… 𝑛 ,𝑛
𝑖=1
𝑖 𝑖
𝑥𝑖∗ = (𝑥𝑖 + 𝑥𝑖−1 )/2.
𝑖−1 Arduino and Numerical 𝑛 𝑛
245 = 1,2,
ℎ = ∆𝑥𝑖 (𝑥𝑖∗,)𝑦𝑖 ) (𝑥𝑖 , (𝑦
𝑦 )𝑓(𝑥 ∗𝑖𝑖 =
= 1,2,
1,2, …… ∗, ,
𝑖 ) )/2𝑓(𝑥𝑖 )(𝑦𝑖 𝑛+ 𝑦
𝑛𝑛 (𝑦𝑖 + 𝑦𝑖
)/2
(𝑥𝑖 , 𝑦𝑖 ) 𝑛 𝑓(𝑥 𝑖𝐴 = 𝐴 ℎ=� ℎ� ∗ +∗𝑦
𝑖𝑖 ).
𝑓(𝑥𝑖𝑓(𝑥 𝑖 ).𝑖−1
𝑛𝑖−1
Assuming a constant voltage on the power supply, calculate ∗
the energy consumed by ∗ ∗
𝐴 = ℎ � 𝑓(𝑥𝑖 ). 𝑖=1 𝑖=1 𝑛𝑛𝐴 = 𝐴 ℎ=� ℎ� 𝑖 ). 𝑖 ).
𝑓(𝑥𝑓(𝑥
the loads over an interval 𝑖 = 1,2, of…time,, 𝑛 defined 𝑡1 by𝑡2start𝑖=1 time 𝑡1 and𝑡2end𝑡1time 𝑡2 . During that ∗∗
ℎ = ∆𝑥are 𝐴𝐴 = = ℎℎ� �𝑓(𝑥 𝑓(𝑥𝑖𝑖).).𝑖=1 𝑖=1
interval the ℎ =loads∆𝑥𝑖
𝑖 randomly
, 𝑦𝑖 ,)𝑦𝑖switched
(𝑥𝑖 (𝑥 ) 𝑓(𝑥on ∗ and
𝑖) 𝑖)
𝑓(𝑥 ∗ off.
(𝑦𝑖(𝑦 +𝑖 𝑦+𝑖−1𝑦)/2
𝑖−1 )/2 𝑖=1
𝑖=1
For (𝑥 a constant) voltage𝑛 U𝑖∗ )and a constant (𝑦𝑖 + 𝑦current (𝑥)/2 𝑦𝑖 I), ,𝑦the power 𝑓(𝑥is∗ constant,
∗ 𝑃
(𝑦= +𝑈𝐼. 𝑃 = 𝑈𝐼.
, 𝑦𝑖1,2,
𝑖 𝑖= …𝐴, 𝑛= ℎ𝑓(𝑥 ∗ 𝑖−1 𝑖 ,(𝑥 𝑖) 𝑖) 𝑖)
𝑓(𝑥 𝑖 (𝑦 𝑖𝑦+𝑖−1 𝑦)/2
𝑖−1 )/2
For time-dependent � 𝑓(𝑥 ).
𝑖 = 1,2, … , 𝑛 values 𝑡1 𝑡1of𝑡voltage
2 𝑖𝑡2 𝑃 = and
𝑃(𝑥
(𝑥=𝑖𝑖,current,
𝑈𝐼. 𝑦𝑖𝑖)) 𝑢(𝑡)
𝑈𝐼.
,𝑦 𝑢(𝑡) 𝑓(𝑥 and )) , the power
𝑓(𝑥𝑖∗𝑖∗𝑖(𝑡), (𝑦𝑖𝑖 +
(𝑦 +is𝑦𝑦𝑖−1
also time-
)/2
𝑖−1)/2
dependent. 𝑡1 Instantaneous
𝑡𝑛2 𝑃 = 𝑈𝐼. power 𝑢(𝑡)
𝑖=1
is then calculated𝑖(𝑡),𝑡1 𝑡as 𝑝(𝑡)
1 2 2𝑡 𝑡 = 𝑃𝑢(𝑡)𝑖(𝑡).
=𝑃 𝑈𝐼.
= 𝑈𝐼.Both
𝑢(𝑡) 𝑢(𝑡) and 𝑖(𝑡),
𝑛
, 𝑦𝑖 ) must be
𝑓(𝑥𝑖∗ ) 𝐴 = ℎ �defined and
(𝑦𝑖𝑓(𝑥 available

). between 𝑡𝑡 and 𝑡𝑡 . In our example, the voltage is constant
+∗ 𝑦𝑖 𝑖−1 )/2
11 22
while 𝐴 the
= ℎcurrent
�𝑖=1 𝑓(𝑥 𝑖 ).not, as it depends on the states of the switches S1 and S2. The energy
is
consumed
𝑡2 ∗ 𝑃 = 𝑈𝐼. 𝑢(𝑡)by the loads
𝑖=1
𝑖(𝑡),in the𝑝(𝑡) circuit is
= 𝑢(𝑡)𝑖(𝑡). 𝑃𝑃 = = 𝑈𝐼.
𝑈𝐼.
𝑓(𝑥 𝑖 ) (𝑦 𝑖 + 𝑦 𝑖−1 )/2
(𝑥𝑖∗ ) (𝑦𝑖 + 𝑦𝑖−1 )/2 𝑡2 𝑡2 𝑡2
= 𝑈𝐼. 𝑢(𝑡) =𝑖(𝑡),
𝑊𝑖(𝑡), 𝑝(𝑡) =
� 𝑝(𝑡)𝑑𝑡 � 𝑢(𝑡)𝑖(𝑡).
𝑢(𝑡)𝑖(𝑡)𝑑𝑡 = 𝑈 � 𝑖(𝑡)𝑑𝑡.
𝑈𝐼. 𝑢(𝑡) 𝑝(𝑡) ==𝑢(𝑡)𝑖(𝑡).
𝑡2 𝑡1 𝑡2 𝑡1 𝑡2 𝑡1
𝑡2 𝑡2 𝑡2
𝑊 = � 𝑝(𝑡)𝑑𝑡 = � 𝑢(𝑡)𝑖(𝑡)𝑑𝑡 = 𝑈 � 𝑖(𝑡)𝑑𝑡.
𝑊 = � 𝑝(𝑡)𝑑𝑡The
= �average power= is𝑈 obtained
𝑢(𝑡)𝑖(𝑡)𝑑𝑡 � 𝑖(𝑡)𝑑𝑡as
. energy divided by T,
𝑡1 𝑡1 𝑡1
𝑡1 𝑡1 𝑡1
𝑡2
𝑊 1 𝑡2
𝑃𝑊= 1= 𝑈 � 𝑖(𝑡)𝑑𝑡,
𝑃= 𝑇 𝑈𝑇� 𝑖(𝑡)𝑑𝑡,
=
𝑇 𝑇 𝑡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 𝑎 1 =∗ 102
𝑖 =
𝐴𝑥=
𝑖 .∗
ℎ �2𝑓(𝑥 𝐴 𝑖
=). ℎ � 𝑓(𝑥 𝑖 ).
𝑥𝑖 +𝑥𝑖−1
= . 𝑖 = 1,2,𝑖=1
…,𝑛
𝑖=1
2 𝑎2 = 921
ℎ = ∆𝑥𝑖 𝑖 = 1,2, … ,𝑛
, 𝑦
𝑖 𝑓(𝑥
𝑖 ) ∗
) 𝑓(𝑥 246

(𝑦 )
𝑖 𝑖 + 𝑦𝑖−1 )/2𝑛 𝑖 (𝑦 + 𝑦𝑖−1 )/2 Đ. Herceg, D. Herceg
∆𝑥𝑖 𝑖 𝑖 = 1,2, … , 𝑛 4(𝑎 − 102) 𝑛
𝐴 = ℎ � 𝑓(𝑥𝑖∗ ).𝑟(𝑎) = .
= 𝑈𝐼.𝑡2 𝑃𝑢(𝑡)
= 𝑈𝐼. The
𝑖(𝑡),data𝑖=1for
𝑢(𝑡) = was
𝑖(𝑡),
𝑝(𝑡) sampled
𝑢(𝑡)𝑖(𝑡).
𝑛 by the Arduino,
273 𝐴 = ℎ � the
𝑓(𝑥values

𝑖 ).
were relayed to a PC and
saved in a file.𝐴Then, the power

= ℎ � 𝑓(𝑥𝑡2𝑖 ).𝑥 P was calculated by
𝑖=1 approximating the definite integral
𝑡2 𝑡2
𝑓(𝑥𝑖 )∗ by using
(𝑦𝑖 + 𝑦𝑖−1 )/2one of the numerical
𝑖=1 methods described above.

𝑊 = � 𝑝(𝑡)𝑑𝑡A=(𝑥 �
simple 𝑖 ) C++ program
𝑖 , 𝑦𝑢(𝑡)𝑖(𝑡)𝑑𝑡 =𝑓(𝑥
𝑈𝑖 �)was
𝑖(𝑡)𝑑𝑡
used (𝑦𝑖read
. to the)/2
+ 𝑦𝑖−1 analog input in 1/4 second intervals and
∗ 𝑦
𝑃𝑦𝑖=) 𝑈𝐼. 𝑡1 𝑖 ) print it
𝑓(𝑥
𝑢(𝑡) to the
𝑖(𝑡),
𝑡1 (𝑦 + 𝑦
𝑖 serial )/2
𝑖−1 port. Another program was written in C# to collect the data from the
𝑝(𝑡) = 𝑢(𝑡)𝑖(𝑡).
𝑡1
𝑡1 𝑡2 𝑃 = 𝑈𝐼. 𝑛 𝑢(𝑡) 𝑖(𝑡), 𝑝(𝑡) = 𝑢(𝑡)𝑖(𝑡).
serial port on the
𝑡2
PC and save it into a file. With the program running, lightbulbs were
𝑡2 𝑃 = 𝑈𝐼.
𝑡2 𝑢(𝑡)
𝑊 1
connected
𝑡2
and 𝑖(𝑡), 𝐴 𝑝(𝑡)
disconnected= �=
𝑡2 𝑢(𝑡)𝑖(𝑡).
several

times. Raw
𝑡2 data was converted
𝑡2 to the range from 0V
𝑖 )∆𝑥
𝑓(𝑥𝑡2 𝑖
𝑃 =
𝑊 = � 𝑝(𝑡)𝑑𝑡 = =
� 𝑈 � 𝑖(𝑡)𝑑𝑡
𝑢(𝑡)𝑖(𝑡)𝑑𝑡 = , 𝑈 � 𝑖(𝑡)𝑑𝑡 .
to 5V 𝑡2
using𝑇linear interpolation
𝑇 𝑡2
𝑖=1 in the same way as in the previous exercise. The data was
𝑊 = � 𝑝(𝑡)𝑑𝑡 𝑡2 = � 𝑢(𝑡)𝑖(𝑡)𝑑𝑡 = 𝑈 � 𝑖(𝑡)𝑑𝑡.
𝑡1
𝑡1
scaled and
𝑡1
graphed in Mathematica
𝑡1
(Fig. 6).
𝑊 = � 𝑝(𝑡)𝑑𝑡 ∆𝑥 = 𝑖�=𝑢(𝑡)𝑖(𝑡)𝑑𝑡
𝑥𝑖 − 𝑥𝑖−1 , =𝑡1 ∗ �[𝑥
𝑥𝑖𝑈∈ 𝑖(𝑡)𝑑𝑡 , 𝑥𝑖.𝑡1
]. 𝑡1
To 𝑇
calculate
= 𝑡 2 − 𝑡the
𝑡21
average power, the 𝑖−1
definite integral in
𝑡1𝑊 1 𝑡1 𝑡1 𝑡2
𝑃= = 𝑈 � 𝑖(𝑡)𝑑𝑡, 𝑥𝑖∗ = 𝑥𝑖−1 , 𝑊 1
𝑇 𝑇 𝑡2 𝑡2 𝑃= = 𝑈 � 𝑖(𝑡)𝑑𝑡,
1 𝑊
𝑡1 1 𝑇 𝑇
𝑃= 𝑈 � 𝑖(𝑡)𝑑𝑡 � ∗ = 𝑥,
𝑇 𝑃 = 𝑇 = 𝑇 𝑈 𝑥𝑖(𝑡)𝑑𝑡
𝑡1
𝑖 𝑖
𝑇 = 𝑡𝑡12 − 𝑡1 𝑡1
𝑥𝑖 + 𝑥𝑖−1 𝑇 = 𝑡2 − 𝑡1

𝑡2 𝑇 = 𝑡 𝑥 = .
2 − 𝑡1
𝑖
was approximated
1 with 2
the trapezoidal rule. Since𝑡2the raw data was sampled at regular
𝑃 = 𝑈 � 𝑖(𝑡)𝑑𝑡 1
1/4s intervals,
𝑇 the equidistant
∗𝑡2 form of the𝑃 trapezoidal
= 𝑈 � 𝑖(𝑡)𝑑𝑡 rule was used,
𝑡1 1 𝑥𝑖 = (𝑥𝑖 + 𝑥𝑖−1 )/2. 𝑇
𝑃 = 𝑈 � 𝑖(𝑡)𝑑𝑡 𝑡1
∗ 𝑥𝑖 +𝑥𝑖−1 𝑛 𝑇
𝑥𝑖 = . 𝑦𝑖 + 𝑦𝑖−1𝑡1 𝑛
2
𝐴 = ℎ� 𝑦𝑖 + 𝑦𝑖−1
2 𝑛 𝐴 = ℎ�
𝑖=1 𝑦𝑖 +ℎ𝑦𝑖−1 = ∆𝑥𝑖 2
𝐴 = ℎ� 𝑖=1
2
𝑖=1
since ℎ = ∆𝑥𝑖 = 1/4 for 𝑖 = 1,2, … , 𝑛. The power P was obtained as
∆𝑥𝑖 = 1/4
20�
1 1 𝑦𝑖 + 𝑦𝑖−1
𝑃≈ 𝑈 � = 2.19226𝑊
𝑇 4 2
𝑖=1

Fig. 6. Converting raw data and graphing the results


1 𝑡2 𝑃 = 𝑈𝐼. 0𝑉
𝑢(𝑡) 𝑖(𝑡), 𝑝(𝑡) = 𝑢(𝑡)𝑖(𝑡).
(𝑥0 , 𝑦0 ), (𝑥
𝑇 1=, 𝑦𝑡1 ),−…𝑡, (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, … (𝑥
2 1 𝑇 0=, 𝑦𝑇𝑡02),
=−(𝑥 𝑡𝑇𝑡211=
−, 𝑦𝑡112),−…𝑡,1(𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, … 𝑡2

𝑢 𝑡2 𝑡2 𝑡2 𝑊 = � 𝑝(
𝑡2 𝑛 = 1 (𝑥 , 𝑦 𝑡2), (𝑥 𝑡2 , 𝑦 ),
𝑡2 … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, …
1 𝑊 = � 𝑝(𝑡)𝑑𝑡 = � 𝑢(𝑡)𝑖(𝑡)𝑑𝑡 = 𝑈 � 𝑖(𝑡)𝑑𝑡. 0
1 1 1 0 1 1 𝑡1
𝑃 = 𝑎 𝑈= � 𝑖(𝑡)𝑑𝑡
1023𝑢/5 𝑡1 𝑡1
Arduino and Numerical Mathematics
𝑡1 𝑃 =𝑃 = 𝑈� 𝑃𝑈 =𝑖(𝑡)𝑑𝑡
�𝑈 � 𝑖(𝑡)𝑑𝑡
𝑖(𝑡)𝑑𝑡 247
𝑥 − 𝑥1 𝑇 𝑥 − 𝑥0 (𝑥 − 𝑥0 )(𝑦1 − 𝑦0 ) 𝑇 𝑇 𝑇 𝑛=1
1 (𝑥) = 𝑦0 + 𝑦1𝑡1 = 𝑦0 + . 𝑡1 𝑡1 𝑡1
𝑥0 − 𝑥1 𝑢1 =𝑥 −
1 0.50 𝑥 𝑥 1 −𝑡2 𝑥0
𝑛 𝑊 1 𝑥𝑛 − 𝑥𝑛1 𝑛 𝑥 − 𝑥0 (𝑥 − 𝑥0 )(𝑦1 − 𝑦0 )
𝑦𝑖 + 𝑦𝑖−1 𝑃 = = 𝑈 � 𝑖(𝑡)𝑑𝑡, 𝐿1 (𝑥) = 𝑦0 𝑦𝑖 +𝑦+ 𝑦𝑖𝑖−1
+1 𝑦𝑖𝑖−1
𝑦 + 𝑦𝑖−1= 𝑦0 + .
𝐴 = ℎ� 𝑢2 = 4.5 0𝑉 𝑇 𝑇 𝐴 = 𝐴ℎ �
= 𝐴

𝑥0 − 𝑥1 � = ℎ � 𝑥 −𝑥 𝑥1 − 𝑥0
2 𝑡1 2 2 1 2 0
𝑖=1 𝑖=1 𝑖=1 𝑖=1
𝑎1 = 102 𝑢 𝑇 = 𝑡2 − 𝑡1 0𝑉
ℎ = ℎ∆𝑥=𝑖 = ℎ 1/4
∆𝑥 =
𝑖 = ∆𝑥1/4𝑖 = 1/4
20� 𝑎= 1023𝑢/5 20� 20� 20�
𝑦𝑖 𝑎 2 𝑦= 921 + 𝑦𝑖−1 𝑢
𝑡2
1 1 + 𝑖−1 1Fig. 7. Numerical integration 1 1 11𝑦𝑖 +1𝑦𝑦𝑖𝑖−1 + 𝑦𝑖𝑖−1
𝑃 ≈ 𝑈(𝑥0� , 𝑦 0 ), (𝑥 1 , 𝑦 1
=
), … 2.19226𝑊
, (𝑥𝑛𝑃, 𝑦= 𝑛 ), 𝑈 𝑛 �= 1,2,
𝑖(𝑡)𝑑𝑡 … 𝑃 ≈ 𝑃 𝑈
≈in𝑃 �
≈ �
𝑈 𝑈 � = 2.19226𝑊
Mathematica = 2.19226𝑊
= 2.19226𝑊
𝑇 4 2 𝑢 = 0.5 𝑇 𝑇 𝑇4 4𝑇 4 2 2 2
𝑖=1 4(𝑎 − 102)
1
𝑡1
𝑖=1 𝑖=1 𝑖=1 𝑎 = 1023𝑢/5
(𝑥0𝑟(𝑎)
, 𝑦0 ), =(𝑥1 , 𝑦1273 ), … , (𝑥𝑛. , 𝑦𝑛 ), 𝑛 = 1,2, …
where 𝑦𝑖 𝑢is2 the = 4.5 sample
𝑦𝑖 𝑦𝑖 𝑖at index𝑦𝑖𝑛𝑖 𝑇 = 𝑖, 𝑇209𝑠/4
= 209𝑠/4 = 52.25 and 𝑈 = 𝑈3.5𝑉
= 52.25 = 3.5𝑉. The
𝑢1 = calculation
0.5 in
𝑦𝑖 + 𝑦𝑖−1
Mathematica 𝑥 is𝑛shown = 1𝐴 =inℎ Fig. � 7.
𝑎1 = 102 2
𝑖=1 𝑢2 = 4.5
𝑥 − 𝑥1 𝑦 𝑥 − 𝑥0 (𝑥 − 𝑥0 )(𝑦1 − 𝑦0 ) ℎ = ∆𝑥𝑖 = 1/4
1 (𝑥)
ℎ = 𝐿∆𝑥 =1/4
𝑦0 5. Numerical +𝑎 𝑦 = 921 = 𝑦 + .
𝑖 = 𝑥0 − 𝑥1 2 𝑥1 Differentiation
1
− 𝑥0 0 and
𝑥1 −Curve
𝑥0 Smoothing 𝑎1 = 102 1
𝑛 20� 𝑃≈
1 1 𝑦 𝑖 + 𝑦 𝑖−1 𝑇
𝐴 = � 𝑓(𝑥 𝑃4(𝑎 −𝑈
≈�∗ )∆𝑥 102)
� � = 2.19226𝑊 𝑎2 = 921
Finite𝑟(𝑎) =
difference 𝑇0𝑉 4 .
formulas for
2 numerical differentiation are approximations of deriva-
�=1 273 𝑖=1
tives at a point. They are used to calculate the value of the first derivative 𝑦of
4(𝑎𝑖 − a function
𝑖
102) 𝑇 = 209𝑠/4 = 52.2
∗ 𝑢[𝑥 𝑟(𝑎) = .
𝑦𝑖 𝑖 ∆𝑥�𝑇=for a
=𝑥209𝑠/4
� − given
𝑥 �−1 , = 𝑥 , or
52.25
� ∈ when
�−1 �, 𝑥 the
]. 𝑈 function
= 3.5𝑉 is unknown and only sampled data is available.
273
Geometrically, 𝑎 = a finite difference is the slope of a secant through �𝑥, 𝑓(𝑥)� and �𝑥 ± ℎ, 𝑓(𝑥 ± ℎ)�
1023𝑢/5

�𝑥, 𝑓(𝑥)� �𝑥 ± ℎ,𝑥�𝑓(𝑥 = 𝑥±�−1 𝑦ℎ)� , , which approximates the value of the first derivative at 𝑥,
𝑢1 = 0.5
𝑥�∗ = 𝑓(𝑥 𝑥� ± ℎ) − 𝑓(𝑥) 𝑦
� (𝑥)
𝑓 ≈ .
𝑢 = 4.5
𝑥� + 𝑥2�−1 ℎ
𝑥�∗ = 𝑓(𝑥. ± ℎ) − 𝑓(𝑥)
� (𝑥) 2
A 𝑓symmetric ≈𝑎1 =difference
102 can. also be used,


𝑥� = (𝑥� + 𝑥�−1 )/2.
𝑎2 = 921
𝑓(𝑥 + ℎ) − 𝑓(𝑥 − ℎ)
𝑓 � (𝑥) ≈ .
4(𝑎 −2ℎ 102)
𝑟(𝑎) = .
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

(𝑥0 , 𝑦0 ), (𝑥1 , 𝑦1 ), … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 =(𝑥 1,2,0 , 𝑦… 0 ), (𝑥1 , 𝑦1 ), … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, …


Capacitor C is charged through a resistor. After charging, it is discharged through an-
(𝑥0 , 𝑦other resistor and a red LED. The
0 ), (𝑥1 , 𝑦1 ), … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, (𝑥0… , 𝑦circuit is presented in Fig. 8. The user can choose be-
0 ), (𝑥1 , 𝑦1 ), … , (𝑥𝑛 , 𝑦𝑛 ), 𝑛 = 1,2, …
tween charging and discharging by toggling the switch S. The voltage on C is measured
𝑓(𝑥 ± ℎ) − 𝑓(𝑥)
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.
.
𝑥 − 𝑥1During𝑥charging,− 𝑥0 (𝑥 − 𝑥0𝑥)(𝑦
the −voltage −1𝑥−
across 1 𝑦 0 ) capacitor
the 𝑥 − 𝑥0 depends − 𝑥R0,)(𝑦
(𝑥 on 1−𝑦
C and 0)
input voltage
𝐿1 (𝑥) = 𝑦0 + 𝑦𝑓(𝑥 + ℎ) − = 𝑓(𝑥 + ℎ)
𝑦𝐿01 (𝑥) = 𝑦0 + 𝑦.1 = 𝑦0 + 𝑓(𝑥 + ℎ) − 𝑓(𝑥. − ℎ)
𝑥0 U𝑓 �according
− 𝑥1 ≈ 1 𝑥1 to
(𝑥) − 𝑥the
0 2ℎformula . 𝑥 𝑥
10 − − 𝑥 𝑥
01 𝑥 1 − 𝑥 0 �
𝑓 (𝑥) ≈ 1 𝑥 − 𝑥0 .
𝑓(𝑥 ± ℎ) − 𝑓(𝑥) 2ℎ
� (𝑥)
𝑈� (𝑡) = 𝑈(1 0𝑉 − 𝑒 −𝑡/�� ). 𝑓 ≈
ℎ 0𝑉
.
𝑈𝐶 (𝑡) = 𝑈(1 − 𝑒 −𝑡/𝑅𝐶 ).
𝑢 𝑢 − ℎ)
𝑓(𝑥 + ℎ) − 𝑓(𝑥
The RC time constant 𝜏𝑓 = �
𝑅𝐶≈gives time𝑡required
(𝑥) stop ≈ 5𝜏.to. charge the capacitor to approxi-
2ℎ
𝑓(𝑥mately
± ℎ) 63.2%
−𝑎 𝑓(𝑥)
= of
1023𝑢/5 the charging voltage, or 𝑎to=discharge
1023𝑢/5 the capacitor
𝑓(𝑥 ± ℎ) −� (𝑥) to approximately �
𝑓(𝑥)𝑓(𝑥𝑓(𝑥± ℎ) ±− ℎ)𝑓(𝑥)
− 𝑓(𝑥) 𝑓(𝑥 ± ℎ
𝑓 � (𝑥) ≈ . 𝑓 � (𝑥)𝑓(𝑥
� (𝑥) ≈ ± ℎ)𝑓− 𝑓𝑓(𝑥)
� (𝑥)
≈. ≈
𝑓(𝑥 ±. 𝑓(𝑥
𝑓(𝑥 ℎ)±𝑓(𝑥
−ℎ) 𝑓(𝑥)
−±𝑓(𝑥)
ℎ) .𝑓 𝑓(𝑥)
− . ≈
(𝑥)
36.8%ℎof𝑓(𝑥 its ±
initial
ℎ) − voltage.
𝑓(𝑥) As
𝑈𝐶 capacitor
(𝑡) = 𝑈(1 − 𝑒 𝑓
charging
−𝑡/𝑅𝐶 ≈
and
). discharging
� ℎ are asymptotic
±
ℎ ℎ)
ℎ −pro-
𝑓(𝑥)
𝑓(𝑥 ± ℎ) − 𝑓(𝑥)
𝑓 ℎ(𝑥) �
𝑓 (𝑥) ≈� (𝑥)
𝑓

𝑓≈ (𝑥)
≈ ≈ 𝑓 �ℎ(𝑥) ≈.ℎ . . . .
𝑓 � (𝑥) ≈the 𝑢time
cesses, = to full
𝑓(𝑥
0.5 ± ℎ) . − 𝑓(𝑥)
charge is infinite. An approximate
𝑢 = 0.5 stopping condition ℎ
is sometimes
ℎ ℎ
𝑓 1
� (𝑥)
≈ ℎ𝑓(𝑥 ± ℎ) − 𝑓(𝑥) . 1
𝑓(𝑥 + ℎ) − 𝑓(𝑥
� (𝑥)−
𝑓 as≈𝑡stopℎ) . if the capacitance 𝑓(𝑥 + ℎ) − 𝑓(𝑥𝑓(𝑥 − +ℎ)
𝑓(𝑥 ℎ)
+ −
ℎ) 𝑓(𝑥
− −
𝑓(𝑥 ℎ)− ℎ) 𝑓(𝑥 + ℎ)
𝑓 � (𝑥) ≈ 𝜏 =established
𝑅𝐶 . ≈ 5𝜏. ℎℎ
However, 𝑓(𝑥 ± 𝑓 �−(𝑥) ≈ and
𝑓(𝑥 + ℎ)𝑓 resistance
− � 𝑓(𝑥
(𝑥) ≈−≈
𝑓 � (𝑥) ℎ)in the circuit are
.−ℎ)𝑓(𝑥 . ≈ −. −
2ℎ
𝑓(𝑥 𝑢
+ =
ℎ) 4.5
− 𝑓(𝑥 − ℎ) 𝑓 � (𝑥)
≈ 𝑓 �ℎ)
(𝑥)
𝑢 =≈𝑓(𝑥)
4.5 . 2ℎ 𝑓(𝑥 +𝑓(𝑥
𝑓(𝑥.ℎ)+𝑓(𝑥+ 2ℎ−+2ℎ
ℎ) −ℎ)
𝑓(𝑥 𝑓−�𝑓(𝑥
−𝑓(𝑥
ℎ)
− (𝑥)
ℎ)

+ ℎ) ℎ)𝑓(𝑥 − ℎ
unknown,
𝑓 � (𝑥) ≈
one
2 must use a different
.
stopping criterion,
2 based𝑓 �
on
(𝑥)
𝑓 available
�≈
(𝑥)
2ℎ 𝑓 (𝑥) ≈
� 𝑓≈�
(𝑥) numerical
≈ �
𝑓 (𝑥) ≈ data.
. . . .
𝑓(𝑥 + ℎ)
ℎ) −− 𝑓(𝑥
𝑓(𝑥 − − ℎ)
ℎ) ℎ 2ℎ 2ℎ2ℎ 2ℎ

≈ 𝑓(𝑥 2ℎ + 𝑓(𝑥 ± ℎ) − 2ℎ 𝑓(𝑥)
𝑈𝐶 (𝑡) = 𝑈(1 −𝑓𝑓𝑒�−𝑡/𝑅𝐶(𝑥) ≈
(𝑥) 𝑎1 ).= 102 2ℎ ..
𝑎 = 𝑈
(𝑡)102
𝐶 (𝑡) = 𝑈(1 −𝑈 𝑒
−𝑡/𝑅𝐶
−𝑡/𝑅𝐶 ). �
(𝑡)
𝑈 ).(𝑡)
= 𝑈(1
= 𝑓 𝑈(1− 𝑒≈
(𝑥) −−𝑡/𝑅𝐶
𝑒 −𝑡/𝑅𝐶
). ).𝑈𝐶 (𝑡) = 𝑈(1. −
2ℎ 𝑈
1
𝑓(𝑥 + ℎ) − 𝑓(𝑥 − ℎ) = 𝑈(1 − 𝑒 𝐶 𝐶
−𝑡/𝑅𝐶 ℎ −
𝐶 𝑈𝐶 (𝑡)
𝑈 (𝑡)
=𝐶 (𝑡)
𝑈 𝑈(1
𝑈= (𝑡)
−𝑈(1
𝑈(1
= 𝑒=−𝑈 𝑈(1
𝑒
− ).−
−𝑡/𝑅𝐶
(𝑡)
𝑒 −𝑡/𝑅𝐶
=
−𝑡/𝑅𝐶
𝑒).𝑈(1
). ). 𝑒 −𝑡/𝑅𝐶 ).
𝑈𝐶 Solution
5.2. (𝑡) = 𝑈(1 − 𝑒 −𝑡/𝑅𝐶 ). �
𝑓 (𝑥) ≈ . 𝐶 𝐶 𝐶
≈ 5𝜏. (𝑡)
𝑈𝑎𝐶(𝑡) = = 𝜏𝑈(1
921 = 𝑅𝐶 −𝑡/𝑅𝐶 𝜏
− 𝑒𝑒−𝑡/𝑅𝐶 ).𝑡= 𝑡=
𝜏 𝑅𝐶 𝑅𝐶
stop ≈ 5𝜏. 𝑎2ℎ 𝑡 921
2 =stop
≈ 5𝜏.
𝑡stop 𝜏≈=5𝜏. 𝑅𝐶 𝑡stop ≈𝑓(𝑥5𝜏.+ ℎ) − 𝑓(𝑥 − ℎ)
𝑈 2 𝜏 =
= 𝑅𝐶
𝑈(1 − ). stop ≈ 5𝜏.
𝐶 𝜏 =𝜏𝑅𝐶 =𝜏 𝑅𝐶=𝜏𝑅𝐶 = 𝑅𝐶 𝜏𝑡stop = ≈𝑡stop
𝑡𝑅𝐶
stop5𝜏.
≈𝑡stop
5𝜏.
≈ ≈ 5𝜏.
5𝜏. 𝑡 ≈ 𝑓 �
5𝜏. (𝑥) ≈ .
𝑡stop ≈ 5𝜏. (𝑡) −𝑡/𝑅𝐶 ). stop
𝑓(𝑥is± easily
ℎ) − 𝑓(𝑥)2ℎ
𝐶 = 𝑡1000𝜇𝐹 If5𝜏.
charging voltage 𝑈 = , resistance
U5𝑉 𝑈𝑈
𝑅𝐶=𝑈= R5𝑉
= =5𝑉
and
1𝑘𝛺 𝑈(1 −𝑅𝑒=
capacity 𝑅𝐶1𝑘𝛺= are
C−1𝑘𝛺
1000𝜇𝐹 known, 𝐶 =𝐶 the problem
1000𝜇𝐹
= �1000𝜇𝐹
𝐶 ≈ 4(𝑎 − 102) 4(𝑎 102)
𝑈 = 5𝑉 𝑓 (𝑥)
𝑅 = ≈ 1𝑘𝛺 𝐶 = 1000𝜇𝐹
.
𝐶 𝑡stop ≈solved
5𝜏. 𝑟(𝑎) = 𝑈 = 5𝑉First, 𝑅 = 1𝑘𝛺 𝑟(𝑎) 𝐶 = 1000𝜇𝐹 .
stop
in GeoGebra. . 𝑈 ℎand
273 ≈ 5𝜏. the values , 𝑈𝑅1𝑘𝛺 =and =are defined
=𝑈5𝑉 =𝑈 5𝑉=𝑈5𝑉 = 5𝑉𝑅= ==
𝑅 5𝑉 𝑅1𝑘𝛺
1𝑘𝛺
= 1𝑘𝛺 𝐶𝑅== 𝐶1000𝜇𝐹
= =𝐶1000𝜇𝐹
𝐶 1000𝜇𝐹
1𝑘𝛺 1000𝜇𝐹𝐶 ==1000𝜇𝐹
𝑅 = 1𝑘𝛺 𝐶
==
𝜏𝑈 𝑅𝐶 1000𝜇𝐹 𝑡 273 𝑈𝐶 (𝑡) 𝑈(1 − 𝑒 −𝑡/𝑅𝐶 ).
5𝑉 𝑅== 1𝑘𝛺
1𝑘𝛺 𝐶 (𝑡) is graphed.
𝐶== 1000𝜇𝐹
1000𝜇𝐹 𝑈
𝑈𝐶 (𝑡)𝐶The(𝑡)
stop constant 𝑈𝜏 is
(𝑡)
𝜏 𝑇1 =𝐶 (𝜏,𝐶 0)𝑈 calculated
(𝑡) 𝜏 and𝜏 points
𝑇2 = (5𝜏, 0) 1𝑈𝐶1(𝑡)𝑇 =𝑇 (𝜏,
= (𝜏,
0) 0) and
𝜏 𝑇1 =2𝑓(𝑥 𝑇 =
𝑇 (5𝜏,
=
(𝜏,2 0) (5𝜏,
0) 𝑇are
0)= (5𝜏, 0)
5𝑉 𝑅 𝐶 + ℎ) − 2𝑓(𝑥 − ℎ)
𝑇1 = (𝜏, 0) placed
𝑇2 = (5𝜏, 0) on the 𝑥 axis. Lines perpendicular
𝑈 (𝑡) to the
𝜏 = 𝑅𝐶 𝑈 (𝑡)
𝜏𝑥 axis are 𝑇 placed
1𝑡𝜏= (𝜏, 0)at
� 𝑇 =
𝑓 (𝑥)1 ≈ and (𝜏,𝑇 0)and
= their
(5𝜏, 0)𝑇2 = (5𝜏,. 0)
stop ≈ 5𝜏.
𝐶 𝐶 2
𝑈 = 5𝑉 𝑅 = 1𝑘𝛺 𝐶 = 1000𝜇𝐹 2ℎ
𝜏 𝑇1 = (𝜏, 0)intersections
𝑇2 = (5𝜏,with are defined as A=and B. It is now easily 𝑈𝐶𝑈𝐶observed
(𝜏)/𝑈 = that
𝑈 𝑈
𝐶 (𝑡)𝐶
(𝑡) 𝑈𝐶 (𝜏) 3.161 (𝑡) 0.632 𝑈𝐶 (𝜏) = 3.161 𝑈𝐶
0)
𝑈𝐶 (𝜏) = 3.161 and the ratio 𝑈 𝑦𝐶 (𝜏)/𝑈 = 0.632 equals 63.2%. 𝑦
𝑈𝐶 (𝑡) 𝜏 𝑇1 = (𝜏, 0) 𝑇2 = (5𝜏, 0) 𝑈 = 5𝑉 𝑅 = 1𝑘𝛺 𝑈 𝐶 (𝑡)𝐶 = 1000𝜇𝐹
𝑈(1 − 𝑒 −𝑡/𝑅𝐶 ).
The value 𝑈𝐶 (5𝜏)𝑈=𝐶 (𝜏)/𝑈
𝑈𝐶 (𝜏) = 3.161 4.966𝑉=corresponds
0.632 𝑡 = 5𝜏 to the voltage 220𝛺 across the capacitor 10𝑘𝛺at the end
of
𝑈𝐶 charging.
(𝑡) The slope
𝑈𝐶 (𝜏) of the
= 3.161 graph at𝜏 that
= 𝑅𝐶point
𝑈𝐶 is
(𝜏)/𝑈 found 𝑡 by
= 0.632
stop placing
≈ 5𝜏. the tangent S to 𝑈𝐶 (𝑡)
) = 4.966𝑉 at 𝑡 = 5𝜏. In the example 220𝛺 in Fig. 10 the 10𝑘𝛺 slope is 0.033. Different values of R yield differ-
𝑈ent values
𝐶 (5𝜏) of the slope. For
= 4.966𝑉 𝑡 =example,
5𝜏 𝑈for 5𝑉 and 𝑅 = 1𝑘𝛺
= 220𝛺 10𝑘𝛺the slope 𝐶 is= 0.153
1000𝜇𝐹 and 0.003
respectively.
𝜏 = 𝑅𝐶 𝑡stop ≈ 5𝜏.
𝑈 = 5𝑉 𝑅 = 1𝑘𝛺 𝐶 = 1000𝜇𝐹
𝑈 = 5𝑉 𝑅 = 1𝑘𝛺 𝐶 = 1000𝜇𝐹
𝑈𝐶 (𝑡) 𝜏 𝑇1 = (𝜏, 0) 𝑇2 = (5𝜏, 0)
𝑈𝐶 (𝑡) 𝜏 𝑇1 = (𝜏, 0) Arduino𝑇2 = (5𝜏, 0)
and Numerical Mathematics 249
𝑈𝐶 (𝑡) 𝑈𝐶 (𝜏) = 3.161 𝑈𝐶 (𝜏)/𝑈 = 0.632
𝑈𝐶 (𝑡) 𝑈𝐶 (𝜏) = 3.161 𝑈𝐶 (𝜏)/𝑈 = 0.632
If the 𝑈values for R and C are unknown
𝐶 (5𝜏) = 4.966𝑉 𝑡 = 5𝜏 or unreliable,
220𝛺 a different criterion
10𝑘𝛺 is devised
to stop charging.
𝑈𝐶 (5𝜏) = 4.966𝑉 By sampling
𝑡 = 5𝜏the voltage across
220𝛺 the capacitor during
10𝑘𝛺 charging, an array
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


𝑈𝐶 (𝑡) 𝜏 𝑈𝑈==5𝑉
𝑇1 = (𝜏, 0) 𝑇5𝑉 𝑅𝑅==1𝑘𝛺
2 = (5𝜏, 0)
1𝑘𝛺 𝐶𝐶==1000𝜇𝐹
1000𝜇𝐹 𝑈𝐶 (𝑡) 𝑈𝐶 (𝜏) = 3.161
𝑎 = 1023𝑢/5
𝑈𝐶 (𝑡) 3.161 𝜏𝜏 𝑇𝑇11==(𝜏,
𝑈𝐶 (𝜏)𝑈𝑈𝐶=𝐶(𝑡)
(𝑡) (𝜏, 0) 𝑇𝑇 ==(5𝜏,
𝑈0) (5𝜏,0)
𝐶 (𝜏)/𝑈22= 0.632
0) 𝑈𝐶 (5𝜏) = 4.966𝑉 𝑡 = 5𝜏
𝑢1 = 0.5
250 Đ. Herceg, D. Herceg
𝑈𝐶 (5𝜏) = 4.966𝑉 𝑈𝑈𝐶𝐶(𝑡)
𝑡(𝑡)
= 5𝜏 𝐶𝐶(𝜏)
𝑈𝑈
220𝛺 3.161 10𝑘𝛺 𝑈𝑈𝐶𝐶(𝜏)/𝑈
(𝜏)==3.161 (𝑖, 𝑢𝑖 ),
(𝜏)/𝑈 ==0.632
𝑖0.632
= 1,2, … 𝑖 = 2,3, …
𝑢2 = 4.5
The
(𝑖, 𝑢𝑖 ), 𝑖 = 1,2, … experiment
𝑖= 𝐶(5𝜏)…was
(5𝜏)
𝑈𝑈𝐶2,3, conducted several
==4.966𝑉
4.966𝑉 times,
𝑡𝑡==5𝜏5𝜏 with 220𝛺
220𝛺, 1000𝛺 and 𝜏 10𝑘𝛺
=10𝑘𝛺
10𝑘𝛺resistors
× 1𝑚𝐹 = 10𝑠 1/5
used for charging. For brevity, only 𝑎the 1 = 102
last case is described. In this case
1000𝛺 𝜏 = 10𝑘𝛺 × 1𝑚𝐹 = 10𝑠. Voltage
1/5 data was sampled in 1/5s intervals and saved into a
𝑎2 = 921
file. The data was read into Mathematica, the values were scaled to the correct voltage
range using linear interpolation and graphed4(𝑎 (Fig.
− 11).
102)
The symmetric difference formula𝑟(𝑎) was =used to . numerical approximations to
calculate
273
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-
𝑦 that the slope of the tangent decreases
version and possibly other artifacts. It is obvious
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 programming language. 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
𝑈𝐶 (𝑡) 𝑈𝐶 (𝜏) = 3.161 2ℎ
𝑈𝐶 (𝜏)/𝑈 = 0.632

𝑈𝐶 (5𝜏) = 4.966𝑉 𝑡 = 5𝜏 220𝛺 𝑒 −𝑡/𝑅𝐶 ).


𝑈𝐶 (𝑡) = 𝑈(1 −10𝑘𝛺

254 𝜏 =…
(𝑖, 𝑢𝑖 ), 𝑖 = 1,2, 𝑅𝐶 𝑖 = 2,3, …𝑡stop Đ.
≈ Herceg,
5𝜏. D. Herceg

and gave up
1000𝛺 𝜏 =just
= as
5𝑉they
𝑈 10𝑘𝛺 scored
× 1𝑚𝐹 enough ppoints
𝑅==10𝑠
1𝑘𝛺 𝐶= 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 𝑇1 = (𝜏, 0)
(𝑡) 95%𝜏 confidence (5𝜏,scores
level)𝑇2in=test 0) between the groups (Table 1).

𝑈𝐶 (𝑡) 𝑈𝐶 (𝜏) = 3.161 𝑈𝐶 (𝜏)/𝑈 = 0.632


7.2. Final Testing
𝑈𝐶 (5𝜏) = 4.966𝑉 𝑡 = 5𝜏 220𝛺 10𝑘𝛺
The second test(𝑖, 𝑢was given at the end
𝑖 = of
2,3,the
… experiment. Both groups did the test on pa-
𝑖 ), 𝑖 = 1,2, …
per with the help of Mathematica. During the test it was obvious that the experimental
group was more 1000𝛺 determined
𝜏 = 10𝑘𝛺to complete
× 1𝑚𝐹 =their 10𝑠 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 Mobile Computing & 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 microcontroller boards in teaching.

You might also like