# Spring 2016 MATH 307: Mathematical computing with Mathematica

## Branko Ćurgus

Friday, June 3, 2016

• Today we further discussed Problem 4 on Assignment 3. I modified the yesterday's notebook 20160602_A3_Pr4.nb. More information about the construction done in this notebook is in the file vonKoch_curve.nb. Also, reading the file PythagorasTree.nb will be a useful.
• Today we also discussed Problem 3 on Assignment 3. The notebook 20160603_A3_Pr3.nb contains the discussion. A problem similar to Problem 3 is solved in ExpfTanl.nb.
• We did not discuss Problem 2 on Assignment 3. I hope that you will be able to construct while loops and other commands necessary to solve this problem. I solved some similar problems in Twin_primes.nb.

Thursday, June 2, 2016

• We discussed Problem 4 on Assignment 3 today. The notebook 20160602_A3_Pr4.nb contains the discussion.

Tuesday, May 31, 2016

• We discussed Problem 1 on Assignment 3 today. The notebook 20160531_A3_Pr1.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 Friday, June 10, 2016 at 11:59:59pm.

Friday, May 27, 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 20160527_A3_Pr1.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 commented 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.

Thursday, May 26, 2016

• We discussed Problem 3 on Assignment 2 today. The notebook 20160526_A2_Pr3.nb contains the discussion.

Tuesday, May 24, 2016

• We discussed Problem 4 on Assignment 2 today. The notebook 20160524_A2_Pr4.nb contains the discussion.

Monday, May 23, 2016

• We continued the discussion of Problem 2 on Assignment 2 today. The notebook 20160523_A2_Pr2.nb contains the discussion.

Friday, May 20, 2016

• We discussed Problem 2 on Assignment 2 today. The notebook 20160520_A2_Pr2.nb contains most of the discussion. In this notebook I solved a problem that is similar to what you are asked to do in Problem 2. Towards the end of my solution I used an interesting Pure Function combined with the shortened version /@ of Map[]. When working on constructions like presented in 20160520_A2_Pr2.nb it is essential that you have good geometric understanding on what you want to construct. Then proceed to obtaining a very simple working Manipulation[]. Only after having a very simple properly working Manipulation[] proceed towards getting it beautified.

Thursday, May 19, 2016

• We discussed Problem 3 on Assignment 2 today. The notebook 20160519_A2_Pr3.nb contains most of the discussion. 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[].

Wednesday, May 18, 2016

• We discussed Problem 1 on Assignment 2 yesterday. The notebook 20160517_A2_Pr1.nb contains most of the discussion. In this notebook I solved a problem similar, but simpler than Problem 1. Please be careful with your reasoning in this problem. Rigorously verify your claims.
• Notice that in the notebook 20160517_A2_Pr1.nb I introduced the concept of the Pure Function and how this concept is used with the command Map[]; although I prefer a shortened version of Map[] using /@. Some simple and some more complicated examples are in 20160517_A2_Pr1.nb.

Monday, May 16, 2016

• Very important tools in Mathematica and on this assignment are Module[] and Pure Function. I will talk about them in class.
• Assignment 2 is has been posted today. Comment about the problems are below.
• 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, May 12, 2016

• We discussed Problem 4 on Assignment 1 today. The notebook 20160512_A1_Pr4.nb a solution to a similar problem.
• 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 20160512_A1_Pr4.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, May 10, 2016

• We discussed Problem 3 on Assignment 1 today. The notebook 20160510_A1_Pr3.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.

Monday, May 9, 2016

• We discussed Problem 2 on Assignment 1 today. The notebook 20160509_A1_Pr2.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 20160509_A1_Pr2.nb I present some features of the Mathematica command Graphics[].

Friday, May 6, 2016

• Assignment 1 is due on Monday, May 16, 2016.
• We discussed Problem 1 today. The notebook 20160506_A1_Pr1.nb contains some hints. Yesterday I posted about other aspects of Problem 1.

Thursday, May 5, 2016

• Assignment 1 is has been posted today. 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 will be announced on Monday. It is essential that you start working on the assignment now.
• Your homework notebooks should be organized neatly. The organization should follow the format of my assignment notebook 201620_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.
• We started discussing some aspects of Problem 1 in the notebook 20160505.nb.
• 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.

Tuesday, March 29, 2016

• Mathematica part of the class will start on Monday, May 2, 2016.
• 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.