# Summer 2014 MATH 307: Mathematical computing with MathematicaBranko Ćurgus

Tuesday, August 18, 2014

• In today's file 20140818.nb I indicated how to deal with questions 5 and 6 in Problem 1. I also demonstrated how to create an inverse function for a function which has an inverse which Mathematica does not know.
• In Part (a) in Problem 2 I ask you to reproduce several pictures from Wikipedia's page about Goldbach's conjecture. The first picture at that Wikipedia page is quite interesting, but, to create it in Mathematica involves some effort. Since we do not have much time left, I constructed that picture in the file Goldbach_Picture.nb. Remaining three illustrations at Wikipedia's page about Goldbach's conjecture deal with the number of Goldbach's partitions of even numbers. The first picture shows the number of Goldbach's partitions of even numbers up to 60, the second one includes even numbers up to 1000 and the third one even numbers up to one million. I hope that you will be able to create a command that will efficiently cover all even numbers up to 500000. Let me know how it goes.
• I hope that for Problem 2 you will benefit from reading my notebook Twin_primes.nb.
• I hope that for Problem 3 you will benefit from reading my notebook ExpfTanl.nb. I created ExpfTanl.pdf so that you can read it when Mathematica is not available.
• I hope that for Problem 4 you will benefit from reading my notebooks vonKoch_curve.nb and PythagorasTree.nb. I created PythagorasTree.pdf so that you can read it when Mathematica is not available.
• In Thursday's file 20140814.nb I did a problem which inspired Problem 1 on Assignment 3. The code that in this notebook is a remarkable example of compactness of Mathematica's code.

Thursday, August 14, 2014

• Assignment 3 has been posted today.
• In Problem 1 you need to use the Calendar package: Needs["Calendar`"]. This package contains several functions related to date arithmetic: DaysBetween[], DaysPlus[], DateQ[].
An important warning: Before you use the commands from the Calendar package you must load the Calendar package. If you by mistake try to use one of the Calendar package commands without having the package loaded, you will have to quit the kernel (Evaluation→Quit Kernel→Local) before loading the package.
• The commands Fit[] and FindFit[] are essential for Problem 2 (b-3) on Assignment 3.
• Problem 3 is quite similar to the problem solved in ExpfTanl.nb. In the notebook ExpfTanl.nb there are many hints on what to do in Problem 3.
• The files vonKoch_curve.nb and PythagorasTree.nb are "guides" for the construction of fractals in Problem 4.
• In the first part of Problem 4 you are asked to create a function that would produce iterations of the quadratic type 2 curve. In the first picture below I show the 0th iteration in blue and the 1st iteration in red. I emphasize the points that are used. You do not need to do this on your plots. In the second picture below I show the 1st iteration in blue and the 2nd iteration in red. The large picture is the fourth iteration of the quadratic type 2 curve.
• In the second part of Problem 4 you are asked to create a function that would produce iterations of the Cesaro fractal which depends on angle $\alpha$. The four pictures below show the 0th, 1st, 2nd and the 3rd iteration of the Cesaro fractal with the small angle $\alpha = \pi/16$.

• Below is an animated gif file that cycles through the 1st, 2nd, 3rd, 4th, 5th and the 6th iteration of the Cesaro fractal and, within each of the iterations cycles through all the angles starting from $\pi$, proceeding towards $0$ and then back to $\pi$ in steps of $\pi/50$. The animation starts by the first iteration and cycles through angles from $\pi$ to $0$ and back to $\pi$. This is repeated for 2nd, 3rd, 4th 5th and 6th iteration. For each iteration there are 101 pictures.

• Place the cursor over the image to start the animation.

Tuesday, August 12, 2014

• Assignment 2 is due 11:59 pm on Wednesday, August 13, 2014. You should name your assignment Yourlastname_A1.nb. This file should be placed in your Dropbox directory Dropbox\307_Yourlastname that you shared with me. Please do not save anything else except your assignments in this directory. Also, please do not modify any files that are in the directory Dropbox\307_Files. You are welcome to post your questions as Mathematica notebooks in Dropbox\307_Files\Your_Questions.
• A problem related to Problem 1 is studied in 20140805.nb.
• The notebook 20140807.nb deals with a problem similar to Problem 2.
• Some hints for Problem 3 are in 20140806.nb. In this notebook there is a motivation for the function Module[] and an example how to use Module[]. In 20140812.nb you can find how to provide a geometric illustration for Problem 3.
• In 20140811.nb you can find some hints for Problem 4. Further hints for Problem 4 are in Q_20140812_1_a.nb.

Tuesday, August 5, 2014

• The second assignment has been posted today.
• Very important tools in Mathematica are Module[] and Pure Function. I will talk about them in class.
• Problem 1 is an exploration of a surprising function. You should use what you learned in Calculus combined with the power of Mathematica. The function given in this problem has some surprising features that you need to discover. When you discover these features, formulate them in clear answers to my questions. Support your answers with calculations and illustrations. To explore the function use the functions D[] to find the derivative and FullSimplify[] to simplify it. To find special points you can use Solve[], Reduce[] or FindRoot[] where appropriate. However, Mathematica needs a lot of human help in this problem.
• Problem 2.
• In the first part of this problem you need to unify, as explained in the problem, three animations given below.

Place the cursor over the image to start the animation.

Place the cursor over the image to start the animation.

Place the cursor over the image to start the animation.

• In the second part of this problem you need to reproduce two pictures from Wikipidia's Cardioid page I made an animation that unifies these two pictures. You should be able to produce something like this. If not you can present one animation and one picture.

Place the cursor over the image to start the animation.

• In the third part of Problem 2 you need to produce generalized cardioids. The animations below are large. On a slow internet connection it takes a while for them to load.
• Below is the cardioid generated by a wheel with radius 1/2 rolling on a circle with radius 1.

Place the cursor over the image to start the animation.

• Below is the cardioid generated by a wheel with radius 1/3 rolling on a circle with radius 1.

Place the cursor over the image to start the animation.

• Below is the cardioid generated by a wheel with radius 2 rolling on a circle with radius 1.

Place the cursor over the image to start the animation.

• Below is the cardioid generated by a wheel with radius 3/2 rolling on a circle with radius 1.

Place the cursor over the image to start the animation.

• The file Probabilities.nb deals with questions which are similar to questions in Problem 3.
• I will comment on Problem 4 in class.

Friday, August 1, 2014

• Assignment 1 is due 11:59 pm on Monday, August 4, 2014. You should name your assignment Yourlastname_A1.nb. This file should be placed in your Dropbox directory Dropbox\307_Yourlastname that you shared with me. Please do not save anything else except your assignments in this directory. Also, please do not modify any files that are in the directory Dropbox\307_Files. You are welcome to post your questions as Mathematica notebooks in Dropbox\307_Files\Your_Questions.
• Problem 3 was discussed in 20140731.nb. In Problem 3 you will use combinations of functions FullSimplify[], Sum[], Table[], Range[], Permutations[] and probably others. Problem 3 is inspired by the identity $\frac{\bigl(\sin(3\pi/7)\bigr)^2}{\bigl(\sin(\pi/7)\bigr)^4} +\frac{\bigl(\sin(\pi/7)\bigr)^2}{\bigl(\sin(2\pi/7)\bigr)^4} +\frac{\bigl(\sin(2\pi/7)\bigr)^2}{\bigl(\sin(3\pi/7)\bigr)^4}=28.$ In part A-3 I ask you to explore analogous expressions when 7 is replaced by 5 and the analogous expressions when 7 is replaced by 9. An analogous expression involving 5 will have fewer summands than the given expression (in fact it will have two summands). An analogous expression involving 9 will have more summands than the given expression (in fact it will have four summands).

Wednesday, July 30, 2014

• Today we discussed Problem 4.
• The problem which is alike Problem 4 is as follows: Given three noncollinear points, find the center of the circle that passes through each of the given points. As we have seen in 20140730.nb, Mathematica easily solves this problem symbolically. Given points $A = (A_x, A_y)$, $B = (B_x, B_y)$, $C = (C_x, C_y)$, we seek the point $S = (x,y)$ (the center of the circle) which is at the same distance, say $r$, from each of the points $A$, $B$, $C$. That is, we need to solve for $x, y, r$ the following system of equations: \begin{align*} \sqrt{(A_x - x)^2 + (A_y-y)^2} & = r \\ \sqrt{(B_x - x)^2 + (B_y-y)^2} & = r \\ \sqrt{(C_x - x)^2 + (C_y-y)^2} & = r \end{align*} Mathematica is very efficient in solving this system. It finds: \begin{align*} x & = \frac{B_x^2 \left(C_y-A_y\right)+C_x^2 \left(A_y-B_y\right)+\left(B_y-C_y\right) \left(A_x^2+\left(A_y-B_y\right) \left(A_y-C_y\right)\right)} {2\left(C_x \left(A_y-B_y\right)+ A_x\left(B_y-C_y\right)+ B_x \left(C_y-A_y\right)\right)} \\[10pt] y & = \frac{ A_x\left(B_x^2-C_x^2+B_y^2-C_y^2\right) +C_x \left(A_y^2-B_y^2\right) +B_x \left(C_x^2-A_y^2+C_y^2\right) +\left(C_x-B_x\right) A_x^2 -B_x^2 C_x}{2\left(C_x \left(A_y-B_y\right) +A_x\left(B_y-C_y\right) +B_x\left(C_y-A_y\right)\right)} \\[10pt] r & =\frac{1}{2} \sqrt{ \frac{\left(\left(A_x-B_x\right)^2+\left(A_y-B_y\right)^2\right) \left(\left(A_x-C_x\right)^2+\left(A_y-C_y\right)^2\right) \left(\left(B_x-C_x\right)^2+\left(B_y-C_y\right)^2\right)} {\left(C_x \left(B_y-A_y\right)+B_x \left(A_y-C_y\right)+A_x \left(C_y-B_y\right)\right)^2}} \end{align*} With a little bit of human help these expressions can be brought to a more symmetric form: \begin{align*} x & =\phantom{-} \frac{\left(A_y-B_y\right) \left(A_y-C_y\right) \left(B_y-C_y\right) + A_x^2 \left(B_y-C_y\right)+C_x^2 \left(A_y-B_y\right)+B_x^2 \left(C_y-A_y\right)}{2 \bigl(\left(A_x-B_x\right) \left(B_y-C_y\right)-\left(B_x-C_x\right) \left(A_y-B_y\right)\bigr)} \\[10pt] y & = -\frac{\left(A_x-B_x\right) \left(A_x-C_x\right) \left(B_x-C_x\right)+A_y^2\left(B_x-C_x\right) + B_y^2 \left(C_x-A_x\right) + C_y^2 \left(A_x-B_x\right) }{2 \bigl(\left(A_x-B_x\right) \left(B_y-C_y\right)-\left(B_x-C_x\right) \left(A_y-B_y\right)\bigr)} \\[10pt] r & = \frac{\sqrt{ \left(\left(A_x-B_x\right)^2+\left(A_y-B_y\right)^2\right) \left(\left(A_x-C_x\right)^2+\left(A_y-C_y\right)^2\right) \left(\left(B_x-C_x\right)^2+\left(B_y-C_y\right)^2\right)}} {2\bigl| \left(A_x-B_x\right) \left(B_y-C_y\right)-\left(B_x-C_x\right) \left(A_y-B_y\right) \bigr|} \end{align*} This circle is known as the circumscribed circle of the triangle $ABC$.

Tuesday, July 29, 2014

• Today we discussed Problem 1 and Problem 2.
• Problem 2 is discussed in 20140729.nb. There is some more useful stuff for Problem 2 at my Mathematica page, Section: Recursively defined functions. There are two kinds of functions in this problem: recursively defined functions and functions given by closed form expressions, that are defined in terms of the variable and known functions. These different kind of functions are defined differently in Mathematica. Do not mix two kinds of definitions. This is pointed out in Section: Recursively defined functions.
• I remind you that each definition of a function in Mathematica should be preceded by Clear[];. Inside Clear[] you place the name of your function and all the variables that you are using.
• I also remind you that before saving your work delete all output cells in your notebook. This is done in the menu item (keyboard shortcut ). When you open your notebook again you can easily evaluate all notebook by (keyboard shortcut ).

Monday, July 28, 2014

• Assignment 1 is due on Monday, August 4, 2014. You should name your assignment Yourlastname_A1.nb. This file should be placed in your Dropbox directory Dropbox\307_Yourlastname that you shared with me. Please do not save anything else except your assignments in this directory.
• Your homework notebooks should be organized neatly. The organization should follow the format of the notebook 201430_A1.nb. A notebook should start with a title cell. In a separate cell should be your name. Individual assigned problems should be presented as sections. More about organization of your notebook you can find in the information sheet. One of the posted movies at my Mathematica page explains how to organize your homework notebooks. I pointed that out in my comments.
• Today we discussed Problem 1 in class. Below is the summary of the discussion.
• Problem 1. This problem was discussed in 20140728.nb. In this file I showed how to define a funny trigonometric function based on a parabola. I used Mod[] function. There is another way to define such a function using ArcSin[Sin[x]]. More about this you can find in More_on_Trig.nb file. As we saw in class, you might experience problems with Plot[]; the graph of a funny trig function being not connected. These problems are caused by the plot option Exclusions➜Automatic. Changing Exclusions➜Automatic to Exclusions➜None might fix the problem.
• For Problem 1 you will need to carefully read the file TheBeautyOfTrigonometry.nb. Please pay attention to tricks that I introduce in that file. Reading this file should be a learning experience.
• When you adopt the content of The beauty of trigonometry to your funny Cos, Sin it is essential to pay attention to the proper domains for the variables involved. Here proper means that there should be no overlap in the parametric plots. In 3-d parametric plots overlaps can slow down plotting considerably. Your notebook should evaluate in less than 60 seconds. If it is slower, then comment out the slow parts. That is enclose the slow parts in (*    *). There are several examples in Primer2014.nb.
• Remember that each definition of a function in Mathematica should be preceded by Clear[];. Inside Clear[] you place the name of your function and all the variables that you are using. Please let me know if I did not follow my own rule in some of my files. I call this rule PPP for Prudent Programming Practice.
• Finally, since in our work we produce a lot of pictures our Mathematica files can be quite big. To avoid saving big files (which are more likely to have problems) before saving your work delete all output cells in your notebook. This is done in the menu item (keyboard shortcut ). Since our code will easily recreate all output cells there is no harm in doing this. You can evaluate all notebook by (keyboard shortcut ).

Tuesday, July 22, 2014

• Mathematica part of the class will start on Wednesday, July 23, 2014.
• The information sheet
• We will use
which is available in BH 215. This is the current version of this powerful computer algebra system.
• To get started with Mathematica see my Mathematica page. Please watch the videos that are on my Mathematica page before the first class. Watching the movies is essential for being able to organize your homework notebooks well! I will not discuss the basics of notebook structuring.
• We also have
which is available on many more campus computers. This is an old, but still powerful, version of this software. These two versions are not compatible.