# Summer 2017 MATH 307: Mathematical computing with Mathematica

## Branko Ćurgus

Thursday, August 17, 2017

• Yesterday and today we discussed some aspects of Problem 4 on Assignment 3. The relevant notebook is 20170816_A3_P4.nb. Another relevant notebooks are PythagorasTree.nb and vonKoch_curve.nb.
• Assignment 3 is due tomorrow Friday, August 18, 2017 at 11:59pm.

Tuesday, August 15, 2017

• We discussed some aspects of Problem 3 on Assignment 3. The relevant notebook is 20170815_A3_P3.nb.

Monday, August 14, 2017

• We discussed Problem 1 on Assignment 3 on Friday. In this problem 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.
• Today we discussed Problem 2 on Assignment 3. The notebook which is relevant to Problem 2 is Twin_Primes.nb. The methods presented in the notebook Twin_Primes.nb will be useful for solving Problem 2. The notebook that I created today is 20170814_A3_P2.nb.
• Tomorow we will discuss Problem 3 on Assignment 3. I will almost solve this problem.

Thursday, August 10, 2017

• Assignment 3 has been posted yesterday. Today we did Problem 1. The relevant notebook is 20170810_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.

Wednesday, August 9, 2017

• Today we discussed some aspects of Problem 4 on Assignment 2. The relevant notebook is 20170809.nb.
• Assignment 2 is due tomorrow Thursday, August 10, 2017 at 11:59pm.

Tuesday, August 8, 2017

• At your request we discussed some aspects of Problem 3 on Assignment 2. The relevant notebook is 20170808_A2_P3.nb.

Monday, August 7, 2017

• At your request we discussed some aspects of Problem 2 on Assignment 2. The relevant notebook is 20170807_A2_P2.nb.

Thursday, August 3, 2017

• We considered problems related to Problem 3 today. The relevant notebook is 20170803_A2_P3.nb.
• The file Probabilities.nb deals with questions which are similar to questions in Problem 3.
• Very important tools in this problem, and in general, are Module[] and Pure Function. Please pay attention how I use them in the notebooks cited here.

Wednesday, August 2, 2017

• This week we are working on the problems from Assignment 2.
• We did Problem 1 on yesterday. The relevant notebook is 20170801_A2_P1.nb.
• Today we worked on Problem 2. The relevant notebook is 20170802_A2_P2.nb.

Tuesday, August 1, 2017

• Assignment 2 is has been posted today. Comments about the problems are below.
• Very important tools in Mathematica and on this assignment are Module[] and Pure Function. We have seen examples of pure functions when we used FindSequenceFunction[] in Problem 3 on Assignment 1. I will talk about these two objects more 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.
• 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.

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 27, 2017

• Today we discussed Problem 4 on Assignment 1. The notebook 20170727_A1_P4.nb contains this 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 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 20170727_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.
• Please notice that it is a good practice to save your notebooks with the all output deleted. You delete all output by the keyboard sequence Alt+c l (that is Alt letter c and letter l), or with the manu item Cell ⇾ Delete All Output.
• Recreating deleted output is easy: you can evaluate the entire notebook by the keyboard sequence Alt+v o or with the manu item Evaluate ⇾ Evaluate Notebook

Wednesday, July 26, 2017

• Today I made some comments about Problem 1 and Problem 2 on Assignment 1. I modified the notebooks in which I discussed these problems. Today we discussed thoroughly Problem 3 on Assignment 1. The notebook 20170726_A1_P3.nb contains this discussion. Notice that while studying Problem 2 on Assignment 1 in the notebook 20170725_A1_P2.nb we encountered the concept of Pure Function which is very important in Mathematica.

Tuesday, July 25, 2017

• We discussed Problem 1 and Problem 2 on Assignment 1 today. The notebook 20170725_A1_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. In your homework please make clear which functions are recursively defined and which are defined by closed form expression. Read more about recursively defined functions on my Mathematica page.

Monday, July 24, 2017

• We discussed Problem 1 on Assignment 1 today. The notebook 20170724_A1_P1.nb contains parts of the discussion. In this notebook I explain how to define functions in Mathematica. I also give big hints how to define the specific functions SqSin[], LiSin[], TrapSin[] which are requested in Problem 1.

Thursday, July 20, 2017

• The notebooks that I created yesterday and today in class are 20170719.nb and 20170720.nb. You can find these file in this class' folder on K-drive and in our shared folder on Dropbox.
• In this class' folder on K-drive and in our shared folder on Dropbox you can also find some other helpful files. For example the file Primer.nb is a file that provides an overview of many features of Mathematica. Another file that is very important for the first assignment is TheBeautyOfTrigonometry_8.nb. You can read through these notebooks by evaluating cells as you read them. Or, you can evaluate the entire notebook by the keyboard sequence Alt+v o or with the manu item Evaluate ⇾ Evaluate Notebook
• Please review the notebooks mentioned in the previous item. Also, watch the movies linked on my Mathematica page.
• Assignment 1 has been posted today as the file 201730_A1.nb. You can find this file on K-drive in the folder Curgus\307\Problems. You can also find this file in your Dropbox folder in the folder Dropbox\307_Files\Problems. The information about sharing Dropbox folders has been emailed to your WWU email address on Tuesday, July 18, 2017. If you do not have access to Mathematica you can use this pdf printout of 201730_A1.nb to familiarize yourself with the assigned problems.
• The due date for Assignment 1 is Monday, July 31, 2017 at 11:59pm.
• 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.
• Your homework notebooks should be organized neatly. The organization should follow the format of my assignment notebook 201730_A1.nb. See also the pdf printout of 201730_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 on Assignment 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 Primer.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.
• Assignment 2 will be posted on Monday, July 31, 2017. The due date for Assignment 2 is Thursday, August 10, 2017 at 11:59pm.
• Assignment 3 will be posted on Wednesday, August 9, 2017. The due date for Assignment 3 is the last day of classes, Friday, August 18, 2017 at 11:59pm.

Monday, June 26, 2017

• Mathematica part of the class starts on Thursday, July 19, 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.