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

Wednesday, August 14, 2013

• The Assignment 3 has been posted today.
• In Problem 1 on Assignment 3 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.
• The file Probabilities.nb is dealing with a problem which is similar to questions in Problem 3 on Assignment 3.
• The file PythagorasTree.nb is a "guide" for the construction of fractals in Problem 4 on Assignment 3.
• In the first part of Problem 4 on Assignment 3 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 on Assignment 3 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, August 8, 2013

• In today's file 20130808.nb I demonstrated some useful constructions for Problem 3 and Problem 4
• Please do not modify the files in the directory Dropbox\307_Files. If you want to experiment with these files, copy them in your private directory and modify them there.

Wednesday, August 7, 2013

• Today I explained how to make an approximation of an inverse for any one-to-one function using Interpolation[], see 20130807.nb. This is relevant to Problem 1.
• To help you with Problem 4, in today's file I also explained how to construct a line segment between any two points in 3-space. Given points pA and pB as triples of numbers (for example pA={0,1,1} and pB={1,0,0}) the command

Table[ (1-s) pA + s pB, {s, 0, 1, 0.05} ]

will produce 21 points on the line segment connecting pA and pB. If you want more points, you replace 0.05 with a smaller number.
• After class I was asked how to get decimal numbers to display nicely with the same number of decimal digits. I will add an example to today's file 20130807.nb. Here is an example

TableForm[
Table[
{k, 0, 4}
]
]

This will nicely display approximations (with 5 digits total and with three digits to the right of the decimal point) of the first few nonnegative integer multiples of Pi. This is also relevant to Problem 1.

Tuesday, August 6, 2013

• Today I introduced the concept of Pure Function. This concept was repeatedly used in today's file.
• Today I did a problem which is similar, but simpler than, Problem 2, see 20130806.nb.
• In today's file 20130806.nb I started a problem somewhat similar to Problem 3; more tomorrow.

Monday, August 5, 2013

• The second assignment has been posted today.
• Very important tools in Mathematica are Module[] and Pure Function. I will illustrate these tools in class.
• Problem 1. This problem is quite similar to the problem solved in ExpfTanl.nb. In the notebook ExpfTanl.nb there are many hints on what to do in this problem.
• Problem 2 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. It is a very good example of human-machine interaction.
• Problem 3.
• 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 you need to reproduce two pictures from Wikipidia's Cardioid page I made an animation that unifying 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 3 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.

• I will comment on Problem 4 in class.

Thursday, August 1, 2013

• Today I updated the file 20130730.nb. The definition of a parabola inspired trig functions that I used in this file could be very useful for Problem 1.
• In today's file 20130801.nb I illustrated how to get proper graphs of discontinuous functions, like Floor[], or like SqSin[] in Problem 1.

Tuesday, July 30, 2013

• Assignment 1 is due before class on Monday, August 5, 2013. You should name your assignment YourlastnameA1.nb. This file should be placed in your Dropbox directory Dropbox\307_Yourlastname that you shared with me. Please do not write anything else except your assignments in this directory.
• Your homework notebooks should be organized neatly. 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.
• Problem 1. Yesterday and today I showed how to define funny trigonometric function based on a parabola in two different ways: using Mod[] and using ArcSin[Sin[x]], see 20130729.nb. More about this you can find in More_on_Trig.nb. 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 (*    *).
• Some useful stuff for Problem 2 is at my Mathematica page, Section: Recursively defined functions. See also 20130729.nb. There are two kinds of functions in this problem: recursively defined functions and functions given by closed form expressions, that is defined in terms of the variable only. 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.
• For Problem 3 reading Gleason_numbers.nb can be useful. In Problem 3 you use just three functions FullSimplify[], Sum[] and Table[]. This problem 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).
• Tomorrow we will continue discussing a problem relevant to Problem 4: given three noncollinear points, find the center of the circle that passes through each of the given points. As we have seen today, Mathematica easily solves this problem symbolically. Given points $P_1 = (a_1, b_1)$, $P_2 = (a_2, b_2)$, $P_3 = (a_3, b_3)$, we seek the point $C = (x,y)$ which is at the same distance, say $r$, from each of the points $P_1$, $P_2$, $P_3$. That is, we need to solve for $x, y, r$ the following system of equations: \begin{align*} \sqrt{(a_1 - x)^2 + (b_1-y)^2} & = r \\ \sqrt{(a_2 - x)^2 + (b_2-y)^2} & = r \\ \sqrt{(a_3 - x)^2 + (b_3-y)^2} & = r \end{align*} Mathematica is very efficient in solving this system. It finds: \begin{align*} x & = \frac{a_2^2 \left(b_3-b_1\right)+a_3^2 \left(b_1-b_2\right)+\left(b_2-b_3\right) \left(a_1^2+\left(b_1-b_2\right) \left(b_1-b_3\right)\right)} {2\left(a_3 \left(b_1-b_2\right)+ a_1\left(b_2-b_3\right)+ a_2 \left(b_3-b_1\right)\right)} \\[10pt] y & = \frac{ a_1\left(a_2^2-a_3^2+b_2^2-b_3^2\right) +a_3 \left(b_1^2-b_2^2\right) +a_2 \left(a_3^2-b_1^2+b_3^2\right) +\left(a_3-a_2\right) a_1^2 -a_2^2 a_3}{2\left(a_3 \left(b_1-b_2\right) +a_1\left(b_2-b_3\right) +a_2\left(b_3-b_1\right)\right)} \\[10pt] r & =\frac{1}{2} \sqrt{ \frac{\left(\left(a_1-a_2\right)^2+\left(b_1-b_2\right)^2\right) \left(\left(a_1-a_3\right)^2+\left(b_1-b_3\right)^2\right) \left(\left(a_2-a_3\right)^2+\left(b_2-b_3\right)^2\right)} {\left(a_3 \left(b_2-b_1\right)+a_2 \left(b_1-b_3\right)+a_1 \left(b_3-b_2\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(b_1-b_2\right) \left(b_1-b_3\right) \left(b_2-b_3\right) + a_1^2 \left(b_2-b_3\right)+a_3^2 \left(b_1-b_2\right)+a_2^2 \left(b_3-b_1\right)}{2 \bigl(\left(a_1-a_2\right) \left(b_2-b_3\right)-\left(a_2-a_3\right) \left(b_1-b_2\right)\bigr)} \\[10pt] y & = -\frac{\left(a_1-a_2\right) \left(a_1-a_3\right) \left(a_2-a_3\right)+b_1^2\left(a_2-a_3\right) + b_2^2 \left(a_3-a_1\right) + b_3^2 \left(a_1-a_2\right) }{2 \bigl(\left(a_1-a_2\right) \left(b_2-b_3\right)-\left(a_2-a_3\right) \left(b_1-b_2\right)\bigr)} \\[10pt] r & = \frac{\sqrt{ \left(\left(a_1-a_2\right)^2+\left(b_1-b_2\right)^2\right) \left(\left(a_1-a_3\right)^2+\left(b_1-b_3\right)^2\right) \left(\left(a_2-a_3\right)^2+\left(b_2-b_3\right)^2\right)}} {2\bigl| \left(a_1-a_2\right) \left(b_2-b_3\right)-\left(a_2-a_3\right) \left(b_1-b_2\right) \bigr|} \end{align*} This circle is known as the circumscribed circle of the triangle $P_1P_2P_3$.

Wednesday, July 24, 2013

• Your sources for this class are:
• This webpage.
• My Mathematica page.
• Your Dropbox directory Dropbox\307_Files and the directory Math\Curgus\307 on school's K-drive. The contents of these two directories should be identical. Remember that the entire class has access to this directory. Please do not write anything in this directory and do not delete any files from there. You can copy them in your private directory.
• The file Primer2013.nb has a lot of useful general Mathematica information.
• For some assignment problems there are specific related files that you will need to read.
• Each class period I will use Mathematica for various demonstrations. I will save these files with the current date. For example, next Thursday's file will be 20130724.nb.
• Mathematica's help file. I find this help file truly helpful. Use it.
• Remember that only you and I have access to your Dropbox directory Dropbox\307_Yourlastname. This directory is exclusively for submitting your homework assignments.

Tuesday, June 25, 2013

• Mathematica part of the class will start on Wednesday, July 24, 2013.
• 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.
• 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.