Arduino and Numerical Mathematics
Arduino and Numerical Mathematics
2, 239–256 239
© 2020 Vilnius University
DOI: 10.15388/infedu.2020.12
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.
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
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, …
𝑥 − 𝑥� 𝑥 − 𝑥� (𝑥 − 𝑥� )(𝑦� − 𝑦� )
𝐿� (𝑥) = 𝑦� + 𝑦� = 𝑦� + .
𝑥� − 𝑥� 𝑥� − 𝑥� 𝑥� − 𝑥�
242 Đ. Herceg, D. Herceg
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.
𝑎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.
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.
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.
𝑢 𝑡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
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.
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
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).
8. Conclusions
Table 1
Baseline test scores
Table 2
Test scores after the experiment
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