Course PM Module 3 Problem modules Slides and reading Functions, equations and Code geometry Mathematica is mainly a desktop program that you need to buy and download, but there is also a free web-based version at lab.wolframcloud.com/app. This makes it In this module we begin with problems that combine relatively easy to use Mathematica in school, and there are modelling, mathematical problem solving and many educational materials for all levels. There is an programming. It is a good idea to install a Python extensive Mathematica documentation with many distribution with many packages installed, like Anaconda. examples at reference.wolfram.com/language/ (you can (TRY MATHEMATICA ONLINE) find an introductory book at the bottom). Solve the following exercises in the Mathematica online In contrast to Python, which is an open source "programming lab”. programming language, Mathematica is a commercial a) Try 1-1, 2(3+5), 17/7 and N[17/7] computing environment developed by the company Wolfram Research. When it was introduced in 1988, b) Try these, one after another: a=2, b=3, a+b, a=4, Mathematica was one of the first widely available systems a+b, a+b+ for computer based algebra, but it can also do many other c) Try: things. It uses an interactive "notebook" interface. Expand[(x+1)^3] Solve[5x == 25,x] 1 Solve[{ x + y == 2, y - x == 1 },{x,y}] (SIMPLE FORECAST) Integrate[1/(x^4 - 1), x] and D[%] and Simplify[%] In a city, the number of daily bicyclists has been estimated (% means the result of the last calculation) every third year, see the table. d) Define a function with f[x_]:= x^2 and then try f[3] and f[a+b+c] 2009 24 300 e) Try: Table[Random[], 100] 2012 26 800 Floor[Table[Random[], 100]*6 + 1] 2015 29 100 f) Play[Sin[440 2 Pi t], {t, 0, 1}] g) A nice feature of Mathematica is that it has a lot of real a) Find a model (in this case a function), that world data integrated into it. For example, use approximately fits these points, by manually trying out ElementData to get the atomic radius of aluminium – look suitable coefficients for the straight line. There is no need up this function in the Mathematica documentation to see to fit the points exactly, this is perfectly normal for models. how to use it. (Hint: "AtomicRadius") You can use this Mathematica code: h) Copy and paste this one-line program into the p1 = ListPlot[{{9, 24300}, {12, 26800}, {15, 29100}}]; programming lab and run it. Try to understand how it p2 = Plot[ 8000+100x, {x, 0, 25}, PlotStyle -> works. What does it show? Red, PlotRange->{{0,22},{0,40000}}]; ListPlot[Table[ElementData[z, "AtomicRadius"], Show[p2,p1] {z, 118}]] As your answer, show a plot with the original points and your proposed function.

2 b) Also test to plot with Python using plot.py (if you angles to two different landmarks with known positions. don't have matplotlib installed, you can use trinket). This is a classical way to ensure a safe approach. c) For the planning project “CITY 2020”, the city wishes to See this help slide! have an estimate for the year 2020. Use your model to Explain how the position of the ship can be calculated, in make a prediction, and think about what you want to say to sufficient detail so that it can easily be implemented in a anyone who will use your estimate. computer program. We suggest you use Mathematica for any algebraical calculations. PROBLEM SOLVING HINT: (INVESTIGATE MATHEMATICAL always try to solve problems in smaller steps. FUNCTIONS THROUGH CHANGE) b) Implement a Python program that inputs the observations and outputs the position. Have a look at the program function.py (this program uses matplotlib). It creates some well-known mathematical c) (voluntary) What happens if you have three landmarks? functions in a very simple way, by generating them from There are many other variations of this problem for left to right based on their rate of change (the derivative). applications in navigation, surveying etc. a) Carefully study the mechanism of the program and try to understand it. Give some comments. b) Have a look at the curves on the last page. Can you see any similarities with the functions you generated with the program?

(HOMING)

When you approach land in a ship you can establish your position on the chart by using a compass to measure the

3 (EMPIRICAL PHYSICAL this exercise, we ask you to manually try out different functions, and not at this point use any software to help RELATIONSHIP) you automatically fit functions. Otherwise, feel free to use For two related physical variables the following your creativity. Stop when you are satisfied with your relationship has been measured: model (so if you cannot do better, a straight line is ok. But maybe you can?). me distance p1 = ListPlot[{{88.0, 57.9}, {224.7, 108.2}, {365.3, 149.6}, {687.0,228.07}, 88.0 57.9 {4332, 778.434}, {10760, 1428.74}, {30684,2839.08}, {60188, 4490.8}, {90467, 224.7 108.2 5879.13}}]; p2 = Plot[0.04 x, {x, 0, 100000}, 365.3 149.6 PlotStyle -> Red]; Show[p1, p2] 687.0 228.07 4332 778.434 (INSTALL A ) 10760 1428.74 When you do programming, you will often need a text 30684 2839.08 editor to be able to read and write text files of different kinds, including. A text file is any file where the bits of the 60188 4490.8 file are used to encode text in some form. A text file 90467 5879.13 sometimes ends with .txt, but Python files are also text files, although they end in .py. Html documents and many other kinds of files are also text files. (If a file is not encoded as some form of text, it is called a binary file, like Investigate and suggest a mathematical equation describing for example .jpg files for images. If you are curious, you can the relation between these two quantities. For the sake of 4 still open a binary file in the text editor just to see what it b) Implement a program calculating LIX for an arbitrary looks like.) text (txt file). Try it our on a few different texts. Or just try lix.py For Windows you could install (www.geany.org), to understand our program and try it out – then and for Mac you can install BBEdit (www.barebones.com). briefly describe the program in your own words. (You can There are many similar alternatives on both platforms. It is also voluntarily look at lix2.py.) possible to read and write text files with the standard c) (voluntary) You can also have a look at LIX.pdf, which Notes/Anteckningar application (TextEdit on Mac), but is a Mathematica version for LIX. these are not well suited for programming.

(LIX READABILITY CALCULATOR) Self-check There is a model called LIX which with a simple formula • Have you answered all questions to the best of your attempts to estimate how easy a text is to read. The ability? formula is • Is the required information on the front page, file name correct etc.? O 100 L LIX = + M O Do not submit an incomplete module! We are available to help you, and you can receive a short extension if you contact us. Here, O is the number of words, M the number of sentences and L the number of long words (more than 6 letters). a) Try to understand the formula and suggest why you think it has been designed the way it is.

5 6 7