# Summer 2016 MATH 307: Mathematical computing with Mathematica

## Branko Ćurgus

Thursday, August 18, 2016

• We further discussed Problem 4 on Assignment 3 today. I just added the discussion to yesterday's notebook 20160817_A3_P4.nb. Since I addressed most of the issues related to the Cesaro fractal, for the full credit on Problem 4 you will have to produce both the Quadratic type 2 curve and the Cesaro fractal.

Wednesday, August 17, 2016

• We discussed Problem 4 on Assignment 3 today. The notebook 20160817_A3_P4.nb contains the discussion. Also, the files vonKoch_curve.nb and PythagorasTree.nb contain relevant information for constructions of fractals in Problem 4.

Tuesday, August 16, 2016

• Yesterday we discussed Problem 1 and Problem 3 on Assignment 3. We finished discussion of Problem 3 today. The notebook 20160815_A3_P1_P3.nb contains the discussion of both days. Today I also addressed a question related to Problem 1 and my answer is in 20160816_A3_P1.nb.
• The due date for Assignment 3 is Friday, June 10, 2016 at 11:59:59pm.

Thursday, August 11, 2016

• We further discussed Problem 1 on Assignment 3 today. We learned how to say "yesterday" in Mathematica language. That reminded me of that beautiful sad Beatles' song Yesterday.
• We also discussed Problem 2. There are two aspects of testing Goldbach's conjecture that we want to explore here.
• One aspect is finding a partition for a given even number into two primes. Consider for example 98. How to find two primes that add up to 98? First try 98-3=95 which is not a prime. Then try 98-5=93 which is not a prime. Then try 98-7=91 = 13*7 which is not a prime. Then try 98-11=87 which is not a prime. Then try 98-13=85 which is not a prime. Then try 98-17=81 which is not a prime. Then try 98-19=79 which finally is a prime. This process is in fact like made for a While[] loop. I showed how to do While[] loops in class.
• The second aspect is finding all Goldbach's partitions of a given even number. This seems more suited for Select[] command. Consider again 98. The prime candidate for it Goldbach's partitions are the primes {3,5,7,...,47}, that is all the primes between 3 and 48 (including these numbers). Then from these one selects all the primes for which PrimeQ[98-#]& is true. You could almost do this by hand and find out that only 98-19, 98-31 and 98-37 are primes. Thus 98 has three Goldbach's partitions.
• The notebook 20160811_A3_P1_P2.nb contains the discussion with several examples of how to use Select[] command combined with a Pure function as a selection criteria.
• The due date for Assignment 3 is Saturday, August 20, 2016 at 11:59:59pm.

Wednesday, August 10, 2016

• Assignment 3 has been posted today. We started discussing Problem 1. Methods that you need to use for Problem 1 are illustrating a solution of a "billboard math problem". See the file 20160810_A3_P1.nb.
• 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.
• I will comment on Problem 2 and Problem 3 in class.
• 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 9, 2016

• Yesterday and today we discussed Problem 4 on Assignment 2. The notebooks 20160808_A2_P4.nb and 20160809_A2_P4.nb contain the discussion.
• Assignment 2 is due tomorrow by 11:59:59 pm. Please place your homework notebook in the folder that you shared with me. Name your notebook Yourlastname_A2.nb. This helps me keep your notebooks organized.

Thursday, August 4, 2016

• We discussed Problem 3 on Assignment 2 today. The notebook 20160804_A2_P3_P1.nb contains most of the discussion. There is also an important comment about Problem 1. In this notebook I illustrate how to use Mathematica to simulate probability problems. The file Probabilities.nb has more examples of simulations of probability problems. The important new Mathematica function introduced in these files in Module[]. I continue to use Pure Functions combined with the shortened version /@ of Map[].

Tuesday, August 2, 2016

• Very important tools in Mathematica and on this assignment are Module[] and Pure Function. We have seen examples of I will talk about them in class.
• Assignment 2 is has been posted today. Comments about the problems are below. This assignment is due at 11:59pm on Wednesday, August 10. As I mentioned in class the last assignment will be due at 11:59pm on Saturday, August 20.
• Problem 1 is an exploration of a surprising function. The point of the problem is to find accurate answers to the questions that are asked and support them with as rigorous explanations as you can. You should use what you learned in Calculus combined with the power of Mathematica. 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.

Thursday, July 28, 2016

• We discussed Problem 1 and Problem 4 on Assignment 1 today. The notebook 20160728_A1_P1_the_beauty_of_funny_trig_P4.nb contains the discussion.
• 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 the second part of 20160728_A1_P1_the_beauty_of_funny_trig_P4.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 = (S_x,S_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 $S_x, S_y, r$ the following system of equations: \begin{align*} \sqrt{(A_x - S_x)^2 + (A_y-S_y)^2} & = r \\ \sqrt{(B_x - S_x)^2 + (B_y-S_y)^2} & = r \\ \sqrt{(C_x - S_x)^2 + (C_y-S_y)^2} & = r \end{align*} Mathematica is very efficient in solving this system. It finds: \begin{align*} S_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] S_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*} S_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] S_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$.

Wednesday, July 27, 2016

• We discussed Problem 3 on Assignment 1 today. The notebook 20160727_A1_P3_almost_solved.nb contains most of the discussion. In this notebook I almost solved Problem 3. Your task is to understand the methods that I used and apply them to answer the specific questions that I ask in Problem 3.

Tuesday, July 26, 2016

• We discussed Problem 1 and Problem 2 on Assignment 1 today. The notebook 20160726_A1_P1_P2.nb contains parts of the discussion. In this notebook I explain how to define recursive functions in Mathematica. Please notice the big distinction between recursively defined functions and functions defined by closed form expressions. Read more about recursively defined functions on my Mathematica page.
• At the beginning of the notebook 20160725_A1_P1.nb I present some features of the Mathematica command Graphics[].

Monday, July 25, 2016

• Assignment 1 is has been posted on Thursday. Your notebook with solutions should be named 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.
• Assignment 1 is due on Monday, August 1, 2016.
• Your homework notebooks should be organized neatly. The organization should follow the format of my assignment notebook 201630_A1.nb. Your homework 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.
• For Problem 1 you will need to carefully read the file TheBeautyOfTrigonometry_8.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 (*    *). For example, in my Primer2014.nb notebook I commented out several parts that are slow to evaluate.
• 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.

Wednesday, July 20, 2016

• Mathematica part of the class starts today.
• 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. However, you can use v5.2 for your other classes if v8 is not available.