# Winter 2017 MATH 307: Mathematical computing with Mathematica

## Branko Ćurgus

Friday, March 10, 2017

• Today we discussed Problem 4 on Assignment 3. The relevant notebook is PythagorasTree.nb. See also vonKoch_curve.nb and the notes from today 20170310_A3_P4.nb.
• Yesterday we discussed Problem 3 on Assignment 3. I almost solved this problem. See the notebook 20170309.nb.
• See you at the final exam on Tuesday. I will be available to answer your questions during that time.

Tuesday, March 7, 2017

• Today we discussed Problem 2 on Assignment 3. The relevant notebook is Twin_Primes.nb. The methods presented in this notebook will be useful for solving Problem 2. We also briefly discussed Problem 3.

Monday, March 6, 2017

• Assignment 3 has been posted on Friday. We discussed Problem 1 toda. See the file 20170306_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.

Friday, February 24, 2017

• Assignment 2 is has been posted today. Comments about the problems are below. This assignment is due on Monday, March 6. The last assignment will be posted on March 3 and it will be due on Wednesday, March 15.
• 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.
• 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. Please consult 20170224_A2_P1.nb for the work on this problem that we did today in class.
• 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, February 23, 2017

• It is embarrassing to admit but my formulas for LiCos[] and LiSin[] from yesterday are wrong. They are clearly wrong since they give wrong values LiCos[0] = 0 and LiSin[1] = 0. Clearly we should have LiCos[0] = 1 and LiSin[1] = 1. I should have done more testing. Please learn from this and do more testing before you declare something a solution.
• Now for the real solutions. Again, I posted them in the notebook 20170216_A1_P1_P2.nb. Below I give formulas for LiCos[] and LiSin[] in traditional mathematical notation: The LiCos[x] is $\frac{2}{\pi} \arcsin\Bigl( \cos \Bigl( \frac{\pi}{2} x \Bigr) \Bigr)$ The LiSin[x] is $\frac{2}{\pi} \arcsin\Bigl( \sin \Bigl( \frac{\pi}{2} x \Bigr) \Bigr)$
• Today I modified the notebook 20170221_A1_P4.nb by adding the part with the Manipulate[] command to illustrate the solution of the problem that I solved in the first part.

Wednesday, February 22, 2017

• On February 16 we discussed Problem 1 on Assignment 1. During that class I constructed the functions LiCos[] and LiSin[]. In my definition I used the expression (-1)^(1/2 Floor[x, 2]). It turns out that this is not a good idea. In some situations this formula behaves like (-1)^(1/2), that is it introduces the imaginary unit i. This is not a good idea. Therefore I changed the definitions of LiCos[] and LiSin[] in the notebook 20170216_A1_P1_P2.nb. Please check this notebook and change the definitions in your homework assignment.

Tuesday, February 21, 2017

• We discussed Problem 3 and Problem 4 on Assignment 1 today. I added few more commands to the notebook 20170217.nb; pay attention to the command FindSequenceFunction[]; notice that the output of this command is a Pure Function.
• 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 I have demonstrated in 20170221_A1_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$.
• In 20170221_A1_P4.nb I used Graphics[] command to illustrate the solution of the problem in the preceding item. In your solution to Problem 4 you will have to combine Plot[] to plot the parabola and in Plot[] command you should use the option Prolog->{} to plot the given points.

Friday, February 17, 2017

• Today we further discussed Problem 2 and Problem 3 on Assignment 1. The notebook 20170217.nb contains parts of the discussion. In this notebook I almost solved the first part of Problem 3.

Thursday, February 16, 2017

• We further discussed Problem 1 and Problem 2 on Assignment 1 today. The notebook 20170216_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.

Tuesday, February 14, 2017

• Assignment 1 is has been posted on Monday. 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.
• The due date for Assignment 1 is Friday, February 24, 2017.
• Your homework notebooks should be organized neatly. The organization should follow the format of my assignment notebook 201710_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.
• Today in class I created the file 20170214_A1_P1.nb. You can find this file in our folder on K-drive and in our shared folder on Dropbox. In this file I illustrate how to define a function in Mathematica. I also helped you with defining some of the functions for Problem 1 on Assignment 1.

Wednesday, January 4, 2017

• Mathematica part of the class starts on Tueaday, February 7, 2017.
• 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.