9789144151656

Page 1

Mathematics and Statistics with GeoGebra, WolframAlpha and Python

T H O M A S L I N G E FJ Ä R D


Copying prohibited This book is protected by the Swedish Copyright Act. Apart from the restricted rights for teachers and students to copy material for educational purposes, as regulated by the Bonus Copyright Access agreement, any copying is prohibited. For information about this agreement, please contact your course coordinator or Bonus Copyright Access. Should this book be published as an e-book, the e-book is protected against copying. Anyone who violates the Copyright Act may be prosecuted by a public prosecutor and sentenced either to a fine or to imprisonment for up to 2 years and may be liable to pay compensation to the author or to the rightsholder. Studentlitteratur publishes digitally as well as in print formats. Studentlitteratur’s printed matter is sustainably produced, as regards both paper and the printing process.

Art. No 44147 ISBN 978-91-44-15165-6 First edition 1:1 © The author and Studentlitteratur 2022 studentlitteratur.se Studentlitteratur AB, Lund

Printed by Latgales Druka, Latvia 2022

3C

Design: Jesper Sjöstrand/Metamorf Design Group Cover design: Jens Martin Cover illustration: Shutterstock


CONTENTS

1

WHAT IS PROGRAMMING, AND WHY STUDY IT? 11

1.1

1.6

Programming 11 Summation 14 Examples of summation 15 A triangle with unknown angles 23 Summary 27 Challenges 27

2

THEORETICAL ISSUES 29

2.1

2.7

Continuous functions 29 Differentiation 32 Rolle’s Theorem 33 The Mean Value Theorem 36 L’Hospital’s Rule 40 Summary 45 Challenges 45

3

NUMBERS 47

3.1

Differences in precision 49 Basic arithmetic methods with Python 51 Basic arithmetic 53 Composite or prime numbers 54 Numbers and variables 56 Fraction numbers 57 Percentage 60 The commands div and mod 61 The square root 62 The number π (pi) 64 Numbers in other bases 65 Converting measurements 68 Complex numbers 70

1.2 1.3 1.4 1.5

2.2 2.3 2.4 2.5 2.6

3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13


3.18

Second degree equations 74 Completing the square 77 Vector arithmetic 80 Summary 83 Challenges 84

4

VISUALIZING DATA AND FUNCTIONS 85

4.1

4.29

Points and data sets 86 Relation and change: Apples 89 Three payment models for the indoor swimming pool 92 The decrease in value of a new car 94 Throwing a ball 97 Bar charts 99 Functions 100 Linear functions 101 Randomized linear functions 103 Quadratic functions 105 Graphics of quadratic functions 106 Randomized second-degree functions 108 The axis of symmetry of a parabola 110 Logarithms 113 Exponential functions 116 The relation between the logarithm and the exponential 118 Trigonometric functions 120 Some sine and cosine characteristics 121 Degrees or radians 123 Some characteristics of the sine function 124 The cosine function 126 Selecting the accurate domain 128 The tangent function 130 Expansion of the binomial distribution 134 The logistic function 135 Introduction to regression and interpolation 137 Implicit functions 143 Summary 147 Challenges 147

5

SETS AND PROBABILITY 149

5.1

Sets 149 Cardinality 151 The empty set 152

3.14 3.15 3.16 3.17

4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 4.11 4.12 4.13 4.14 4.15 4.16 4.17 4.18 4.19 4.20 4.21 4.22 4.23 4.24 4.25 4.26 4.27 4.28

5.2 5.3


5.26

The number of values in a set 153 Subsets 154 The power set 156 Subsets and numbers 158 The union 159 The intersection (or the cut) 160 Union and intersection 161 The Cartesian product 162 Probability and sets 164 A definition of probability 167 Random numbers 170 Simulate the roll of a dice 170 Heads or tails 172 Binary trees 173 The roll of two dice 176 Estimate the value of π 177 Combinations and permutations 178 Create a seven-digit number 180 Buffon’s needle problem 182 The Venn diagram 185 Statistical inference and normal distribution 189 Summary 193 Challenges 193

6

STATISTICS 195

6.1

6.11

The mean value 195 The median and the mode 197 Histograms 203 The pie chart 205 Variance and variance spread 210 z-values 215 Correlation 219 Correlation and causality 225 Anscombe’s quartet 231 Summary 234 Challenges 234

7

MATHEMATICAL MODELLING 235

7.1

Linear regression and long jump results 236 Non-linear regression 239 Linear regression analysis 242

5.4 5.5 5.6 5.7 5.8 5.9 5.10 5.11 5.12 5.13 5.14 5.15 5.16 5.17 5.18 5.19 5.20 5.21 5.22 5.23 5.24 5.25

6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 6.10

7.2 7.3


7.10

Non-linear regression analysis 244 The mathematical modelling process 245 Number patterns and polynomials 253 Number patterns again 255 From geometry to algebra 257 Summary 259 Challenges 259

8

GEOMETRY, TRIGONOMETRY AND FRACTALS 261

8.1

8.20

Geometry in GeoGebra, Python and WolframAlpha 261 Area and circumference of a circle 264 Area and circumference for a rectangle 265 A triangle 267 The ellipse 271 The constant π 279 Pythagorean triple 282 A surface area 284 A cube 284 Problem solving and geometry 286 Basic trigonometry 287 Area theorems 293 Heron’s formula 294 The radian 294 Chaos theory 296 Fractals 299 The Mandelbrot set 304 The Julia set 306 Summary 307 Challenges 308

9

LIMITS AND OPTIMIZATION 309

9.1

Mathematical definitions of limits 309 Limits and functions 311 Derivatives 314 Derivatives of trigonometrical functions 317 The derivative of a trigonometric product 319 Optimization 320 Summary 330 Challenges 331

7.4 7.5 7.6 7.7 7.8 7.9

8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 8.13 8.14 8.15 8.16 8.17 8.18 8.19

9.2 9.3 9.4 9.5 9.6 9.7 9.8


10

INTEGRAL CALCULUS 333

10.1

Introduction 334 A definite integral 335 Definite trigonometric integrals 336 The density function 337 Area between two curves 339 Area of a special domain 344 Area between three conditions 347 Area between trigonometric curves 348 Parametric form for curves 349 The folium of Descartes 351 The torus 353 The double folium 354 Fermat’s spiral 355 The lemniscate of Bernoulli 357 The Lissajous figure 359 The solid of revolution 361 Complex numbers and differential equations 365 Taylor series 369 Ordinary differential equations (ODEs) of the first order 371 The SIR model 375 Summary 376 Challenges 377

10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11 10.12 10.13 10.14 10.15 10.16 10.17 10.18 10.19 10.20 10.21 10.22

Index 379



1

WHAT IS PROGRAMMING, AND WHY STUDY IT?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

I N M O D E R N LI FE , it is becoming more and more interesting to understand

programming. We can program lawnmowers, vacuum cleaners, and perhaps we will soon be able to use programmable refrigerators. Other things around us that are programmable are bikes, cars, smartphones, electric grids, parking metres, shoes, streetlights and watches. In the years to come, many more devices will become programmable. In this chapter, we will focus on programming for mathematics using the programming environments GeoGebra, Python and WolframAlpha. The book consists of several parts. Mathematical situations and mathematical problems are described in the physical book you are reading now. The code for programming in GeoGebra, Python and WolframAlpha can be found in text in the Codes & Links Library at Studentlitteratur. Some of the code is explained in the physical book, but most of the programming is explained thoroughly in text in the Codes & Links Library. This means that you will sometimes need to switch between those two parts of the book when you study. There will also be some teaching material with programming examples to illustrate concepts and relations in physics, together with solutions to exam questions in mathematics. This first chapter will contain some fairly easy examples of situations or problems that we will solve with programming, for you to see what programming means and how it can be put into practice.

1.1

Programming

Programming environments are good at calculations, summing numbers, solving equations, finding correlations between sets of values and finding the maximal value of a function. In mathematics and physics, we investigate the motion of different projectiles; or perhaps the flight of a golf ball towards a green; heads or tails when tossing a coin; or the throwing of a dice. Programming that kind of situation is also a way to 11


12 | 1 What is pr o gr a mmin g, and why s t udy i t?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

analyse and learn more about the situation. Some situations are difficult to investigate without a computer. Fractals is one such example: they are difficult to draw using only paper and pencil. The three programming environments used in this book have been selected because GeoGebra currently has over 100 million users around the world, while Python is considered the fastest growing text-based programming language in the world and WolframAlpha has over 1.5 billion hits on their website every day. These three programming environments are used by many every day. GeoGebra allows all constructed objects to be programmed in different ways: with buttons, checkboxes, sliders for moving parts, or with an entire object. GeoGebra is programmed to be a teaching tool, and the program will select a graphical representation if possible. GeoGebra can be programmed by either Java Script or GeoGebra Script. Java Script can be difficult to learn. Thus, there are only a few examples on programming in Java Script or GeoGebra Script in this book. We will mainly use GeoGebra 5. If you register at www.geogebra.org you can download the GeoGebra files referred to in this book. When you have downloaded and opened the file in your local GeoGebra (version 5 or 6), you can examine the coding structure in the Algebra window. It is possible to run GeoGebra files on applications in smartphones, other mobile electronic devices, and computers over the Internet. One of the most common text-based programming environments in the world at present is Python, which has an impressive way of hand­ling large integers. Many different programming languages use an integer representation with a maximum of 64 bits. Python, on the other hand, has support for arbitrary-precision integers. This means that we can add 25-digit numbers in Python and get the correct result – something which would not be possible in Excel or GeoGebra. When we program in Python, we need a compiler. This book uses the web compiler repl.it since this will allow us to share the code easily. Register at https://repl.it/repls. When you have done that, you can publish your code and share it with other students and colleagues. If you prefer to install a Python compiler system in your computer, that will also work. Links to repl.it can be executed over any device with an Internet connection, such as smartphones, other mobile electronic devices or computers. Pythonis a more classic programming environment than GeoGebra and WolframAlpha. Python contains the possibility to import many additional code routines and commands when needed, which is a huge advantage. When you program in GeoGebra and WolframAlpha, all


© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

the possible coding is there in the program. In Python, we can import many different modules to call the desired command in the correct way. WolframAlpha is a powerful system for mathematics. It can also answer questions about other subjects. WolframAlpha is available at www.wolframalpha.com, through a computer or through applications in smart phones. At www.wolframalpha.com/examples/Math.html there are many examples of how WolframAlpha can be used in the learning of mathematics in different ways at different levels. You do not need to register at WolframAlpha. Learning by doing refers to a theory of education by the American philosopher John Dewey. The theory is grounded in the notion that students should interact with their environment to adapt and to learn. Dewey’s views were important in establishing practices of progressive education. This book is framed by learning by doing and the methodology of pseudocode and Tinkering. Pseudocode is a programming description that does not require strict programming syntax or underlying technology considerations. It is used to create a rough draft of a program code. Pseudocode summarizes a program’s flow, excluding its underlying details. After you have tested how to write pseudocode over how to add numbers, pseudocode will enable you to learn what adding numbers means at a deeper level. In that sense, the process of programming and the programming environment constitute a sort of amplifier, as well as a reorganization of the content you are studying or programming. Tinkering is a way to learn programming. When learning how to program, you can follow the instructions line by line to write a program. You can also learn by changing some values in a well-functioning code that someone else has written. Tinkering is a common way to solve programming exercises. When we are looking at the code for summarizing the first 9 natural numbers, we also see the possibility of summarizing, for instance, the first 20 natural numbers and how to alter the code to fulfil that purpose. It is possible to amplify our knowledge since programming makes use of more effective processes compared to manual ones, e.g. calculations of different types or perhaps graphical representations. When you use the programming environment, the task is solved in a significantly shorter time and with less power, yet the result will be comprehensive. Furthermore, the programming will result in a reorganization of our cognitive image of the content when we observe invariants, variation and structures in the mathematical content that otherwise might very well have remained hidden. 1 W hat is pr o gr a mmin g, and why s t udy i t? | 13


1.2

Summation

The sum notation:

is common in mathematics. We interpret the signs as: sum all natural numbers from 1 to 100. It will be important for you to be able to move back and forth with the symbols and the numbers you are supposed to sum. Consider the sum (−3) + (−11) + (−19) + (−27). How do we write this in symbolic form? Each number seems to be 8 less than the previous number. The first number is –3 and 5 – 8 = –3.

The summation sign gives –3, –11, –19, –27, resulting in the sum = –60. The type of numbers we use for sums is not always specified. In that case, natural numbers (i.e. non-negative integers) should be used in the summation. 14 | 1 What is pr o gr a mmin g, and why s t udy i t?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

The concept of number is a mathematical foundation used as a measurement of how many items or units (e.g. length, weight, volume, temperature, pressure). A number is an abstract entity that represents an amount in a pre-defined way. In mathematics, numbers are quite different. There are natural numbers, negative numbers (both integers), rational numbers, real numbers and complex numbers. When you use the concept of a number in a programming environment, you must explain to the computer what a number is. In that process, the definition of numbers is also understood more deeply by the programmer. You might regard this as if the programming process will mediate the specifics of the concept number and thereby enrich your concept definition of what a number is. If you are a novice in programming, you should select easy problems when you first try to solve a problem. In several examples in this book, the same methodology for solving a specific problem has been used. Study these methods carefully. The activity of summing numbers has been selected to be examined first, since that process is easy to follow in the code for the three programming environments. It is also possible to use Tinkering and sum other numbers, once you understand how the code works.


Let us look at some examples where summations are required to make the procedure clearer.

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

1.3

Examples of summation

Our three programming environments use the same abbreviation for the summarize command. GeoGebra uses Sum , Python uses sum and WolframAlpha uses sum. We will now explore how we use the three programming environments when we sum different sets of natural numbers.

EXAMPLE: A SUM OF ONE-DIGIT NATURAL NUMBERS The sum of the natural numbers 1 + 2 + 3 + … + 9 is something you should know about and be familiar with. Here, we can investigate how programming may show this addition and summarizing. At the same time, we will learn how to enlarge the situation. The symbolic form is:

To start with we can formulate a pseudocode, halfway to formal language. Make the computer list the first nine natural numbers, Make the computer sum the listed numbers, Print the sum.

The pseudocode above works for GeoGebra, Python and WolframAlpha. In GeoGebra, we define the list of the first nine natural numbers and sum the elements in the list. See figure 1.1.

1 W hat is pr o gr a mmin g, and why s t udy i t? | 15


The code is in chapter 1 in Codes & Links FIGURE 1.1 GeoGebra summarizes the first nine natural numbers.

Please try out the command list1 = (1, 2, 3, 4, 5, 6, 7, 8, 9) and the command sum(list1) in your local GeoGebra program. In Python, we use the commands below, where we must count to x + 1 since Python counts to the number below the last number. x = 9 print(“\n”) for i in range(1, x+1): numbers = range(1, i+1) print(‘ + ‘.join(map(str, numbers)), ‘=’, sum(num-

We get the following result: 1 = 1 1 + 2 = 3 1 + 2 + 3 = The code is in chapter 1 in Codes & Links

1 + 2 + 3 + 4 = 10 1 + 2 + 3 + 4 + 5 = 15 1 + 2 + 3 + 4 + 5 + 6 = 21 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45

The way we code Python also reveals another way of looking at numbers. We see the triangle numbers, which tend to occur when stocking round objects in piles or in combinatorics. WolframAlpha can be commanded with the short sentence 1+2+3+...+9. The three points are important. WolframAlpha draws a second-degree curve through the points (1, 1), (2, 3), (3, 6), (4, 10) …, (9, 45). See figure 1.2.

16 | 1 What is pr o gr a mmin g, and why s t udy i t?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

bers))


The code is in chapter 1 in Codes & Links

FIGURE 1.2

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

WolframAlpha summarizes the first nine natural numbers.

Now you can use Tinkering and expand the summation as you like. You should be able to do that in all three programming environments without too much work.

EXERCISE Sum the first 1,000 natural numbers in all three programming environ­­ ments. The symbolic form is:

EXAMPLE: THE SUM OF ANY SEQUENCE OF NATURAL NUMBERS The sum of 1 + 2 + 3 + … + n is something you might be asked about in class. Although the size of n might vary, programming will help us discuss possibilities and limitations when n varies. Are all sums possible? How often is the sum a number times hundred? Can we vary n so that we get the sum 100? The symbolic form will be

1 W hat is pr o gr a mmin g, and why s t udy i t? | 17


GeoGebra uses the command Sequence(k, k, 1, n) where n is a slider. Thus, the result is linked to the use of a slider. See figure 1.3. The code is in chapter 1 in Codes & Links FIGURE 1.3 GeoGebra summarizes natural numbers.

Python uses the following code: while(number > 0): sum += number

WolframAlpha gets the same sum by the command 1+2+3+...+50. See figure 1.4.

The code is in chapter 1 in Codes & Links

FIGURE 1.4

WolframAlpha summarizes natural numbers.

18 | 1 What is pr o gr a mmin g, and why s t udy i t?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

number -= 1 Python responds: Give the upper limit for the sum 1 + 2 + ... + n: 50 The sum of 1 + 2 + ...+ 50 = 1275


EXAMPLE: THE SUM OF EVEN NATURAL NUMBERS It is also possible to use programming to investigate the sum of even natural numbers such as 2 + 4 + 6 + ...+ n, where n = 2 ∙ k, k ∈ N. This can help us visualize possible sums when n varies. We can ask ourselves questions like:

• How many terms are needed to get a sum larger than 10,000? • Can we get the sum 100?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

GeoGebra once again uses the command Sequence(k, k, 1, n) where n is a slider, so that the result is linked to the use of a slider. See figure 1.5.

The code is in chapter 1 in Codes & Links

FIGURE 1.5 GeoGebra summarizes even numbers to get a sum which exceeds 10,000.

Python needs an upper limit for the summation. That is given by the commands number = int(input(“Give last number for the sum 2 + 4 + ... + n: “)) n = number if number < 0: print(“A positive number is required”) else: sum = 0 for even _ number in range(0, number+2, 2): sum += even _ number print(“\nThe sum 2 + 4 + ...+”, n, “=”, sum)

Results for upper limit 200: Give last number for the sum 2 + 4 + … + n: 200 The sum 2 + 4 + ...+ 200 = 10,100

The code is in chapter 1 in Codes & Links

1 W hat is pr o gr a mmin g, and why s t udy i t? | 19


WolframAlpha is given the command 2 + 4 + 6 +...+ 200. WolframAlpha translates this to a sum of 100 terms, but the results are the same. See figure 1.6.

EXAMPLE: THE SUM OF ODD NATURAL NUMBERS The sum of odd natural numbers such as 1 + 3 + 5 + … + n where n = 2 ∙ k – 1, k ∈ N can also be investigated with programming that helps us visualize possible sums when n varies. We can ask students questions like:

• How many terms are needed to get a sum larger than 10,000? • Can we get the sum 100?

GeoGebra Commands: Sequence(2k-1, k, 1, n) where n is a slider 1 < n < 1,000 with increment = 1. See figure 1.7. In this case, Python needs an upper limit for the summation. Thus, the commands are: number = int(input(“Limit for the sum 1 + 3 + ... + n: “)) n = number if number < 0: print(“Give a positive number”)

20 | 1 What is pr o gr a mmin g, and why s t udy i t?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

FIGURE 1.6

WolframAlpha summarizes the first one hundred even numbers.


else: sum = 0 for odd _ number in range(1, number +1,2): sum += odd _ number print(“\n The sum 1 + 3 + ...+”, n, “=”, sum)

Results: Limit for the sum 1 + 3 + ... + n: 19 The sum 1 + 3 + ...+ 19 = 100

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

WolframAlpha summarizes odd numbers by the command 1 + 3 + 5 + … + 19. See figure 1.8.

The code is in chapter 1 in Codes & Links

FIGURE 1.7 GeoGebra summarizes odd natural numbers to get the sum 100.

The code is in chapter 1 in Codes & Links

FIGURE 1.8

WolframAlpha summarizes odd natural numbers.

1 W hat is pr o gr a mmin g, and why s t udy i t? | 21


EXAMPLE: SUM ALL FOUR-DIGIT NUMBERS DIVISIBLE BY 3 Pseudocodes (the same for all three programming environments):

• We need a variable that we call sum • We define an area where we summarize four-digit numbers • Numbers divisible by three come every third step on the number line. Which is the smallest four-digit number divisible by three?

The code is in chapter 1 in Codes & Links

In GeoGebra, we use the command Sequence. Please see similarities and differences in our three programming environments. The command is Sequence (3k, k, 334, 3333). GeoGebra gets the result 16,501,500.

FIGURE 1.9 GeoGebra summarizes four-digit numbers.

Python defines the numbers in a different way: sum = 0 for number in range(1002, 10000, 3): sum += number print (“The sum is:”, sum)

Result: The sum is: 16501500 In WolframAlpha, we use the following commands: summarize (1002 +1005 + ... + 9999). See figure 1.10.

22 | 1 What is pr o gr a mmin g, and why s t udy i t?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

The number 1,002 is divisible by 3 and must be the first four-digit number with this property. We divide 1,002 by 3 and we get 334. The largest four-digit number divisible by 3 must be 9,999. We divide 9,999 by 3 and get 3,333.


The code is in chapter 1 in Codes & Links

FIGURE 1.10

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

WolframAlpha summarizes four-digit numbers.

The same sum, 16,501,500, is derived from all three environments. Try Tinkering to calculate another sum.

EXERCISE Sum all three-digit numbers divisible by 7. If we know how to sum all four-digit numbers divisible by 3, can we then change the code and sum all three-digit numbers divisible by 7? Try it. If you get into trouble, you will find the code in chapter 1 in Codes & Links.

1.4

A triangle with unknown angles

A triangle Δ ABC has three unknown angles called a, b and c with the following relations. Angle a is 12° larger than angle c. Angle b is 4 times larger than angle c. Determine the size of the angles. A graphical representation of a triangle Δ ABC. See figure 1.11.

The code is in chapter 1 in Codes & Links

FIGURE 1.11

GeoGebra displays a general triangle (without regard to the conditions in the actual problem).

1 W hat is pr o gr a mmin g, and why s t udy i t? | 23


You should already know that a + b + c = 180°. Pseudocodes: a = 12° + c

b = 4 · c

a + b + c = 180°

GEOGEBRA

FIGURE 1.12 GeoGebra’s CAS tool solves a problem with three unknown variables.

Python uses a short code for this problem. It is convenient that we can print and solve at the same time. The code is in chapter 1 in Codes & Links

print(solve((a - 12 - c, b - 4*c, a + b + c - 180),(a, b, c)))

Result: {a: 40, b: 112, c: 28} WolframAlpha is programmed with the following commands: {x = 12 + z}, {y = 4*z}, {x + y + z = 180} We get the same result. See figure 1.13. GeoGebra accepts variables such as ab, b and c or variables such as x, y and z. Python also accepts variables such as ab, b and c or variables such as x, y and z. WolframAlpha needs variables such as x, y and z. Tinkering: You could construct a new triangle with other measurements and relations, or perhaps extract the problem into a quadrangle.

24 | 1 What is pr o gr a mmin g, and why s t udy i t?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

The CAS (Computer Algebra System) tool in GeoGebra adds a number for all statements. We receive the following result. See figure 1.12.


The code is in chapter 1 in Codes & Links

FIGURE 1.13 WolframAlpha can easily handle three unknown variables.

EXERCISE A triangle Δ ABC has three unknown angles called a, b and c, with the following relations: Angle a is 5° larger than angle c. Angle b is 50° larger than angle c + a. Determine the size of the angles.

The code is in chapter 1 in Codes & Links

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

GRAPHICAL REPRESENTATIONS Let us investigate how the programming environments handle a task in a coordinate system. Graph the line f(x) = 2 · x + 2 in a coordinate system where −2 < x < 15. In GeoGebra we use the command Function( 2 x + 2, -2, 15 )

We get the graphical representation in figure 1.14. We adjust the coordinate system manually.

FIGURE 1.14 GeoGebra graphics.

1 W hat is pr o gr a mmin g, and why s t udy i t? | 25


In Python we use the commands x = np.arange(-2, 15, 0.01) f = 2*x+2 plt.plot(x, f) plt.grid()

We get the graphical representation in figure 1.15 by adjusting the coordinate system in the code.

FIGURE 1.15 Python graphics.

In WolframAlpha, we send the code plot 2*x + 2, x = -2 to 15. Note the multiplication sign that WolframAlpha requires. We get the graphical representation in figure 1.16. We adjust the coordinate system in the code.

FIGURE 1.16 WolframAlpha graphics.

26 | 1 What is pr o gr a mmin g, and why s t udy i t?

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

The code is in chapter 1 in Codes & Links


1.5

Summary

In this chapter we have discussed

• • • • • • •

our three programming environments what programming is, and why pseudocodes and Tinkering summation notation and commands summation of natural numbers summation of specific natural numbers graphical representations of a linear function.

All the graphical representations in the 16 figures in this chapter have been designed to support your learning and understanding of the concepts and methods which have been discussed.

© T H E AU T H O R A N D S T U D E N T L I T T E R AT U R

1.6

Challenges

You can now test Tinkering and change the code in any of the examples in this chapter. You will find the entire coding for GeoGebra, Python and WolframAlpha regarding all the programming examples in the Codes & Links Library. You might also change value parameters or variables to learn how sensitive (or insensitive) the code is. Or you might expand or change the code and thereby make it possible to, for instance, calculate the sum of all three-digit numbers that are divisible by seven. You could also try to solve any other problem related to the code in this chapter.

1 W hat is pr o gr a mmin g, and why s t udy i t? | 27


Thomas Lingefjärd has retired from the position as associate professor in mathematics education at the University of Gothenburg, but he is active as an upper secondary school teacher in mathematics, physics and programming, and as an author of both research articles and books.

Mathematics and Statistics with GeoGebra, WolframAlpha and Python Mathematics and Statistics gives a programming-based approach to solving problems in mathematics and statistics. By giving plenty of examples the book introduces the reader to the basics of GeoGebra, Python and WolframAlpha. Programming has proven to be a fruitful and motivating way to learn mathematics and statistics. Mathematics and Statistics gives students ample opportunities to program, tinker and learn. The book is supplemented by a digital component. Using the code on the inside of the cover, you can reach Codes & Links. Codes & Links contains all the coding in GeoGebra, Python and WolframAlpha, whereas the book itself presents the problems, the theory, and the results. Mathematics and Statistics can be used on introductory university courses in mathematics and mathematical statistics as supplementary material. It can also be used for self-education as a means for finding the much-needed links between programming and mathematics.

Art.nr 44147

studentlitteratur.se


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.