# Spring 2017 MATH 307: Mathematical computing with Mathematica

## Branko Ćurgus

Friday, June 2, 2017

• Today we discussed Problem 2 on Assignment 3. The relevant notebook is Twin_Primes.nb. The methods presented in Twin_Primes.nb notebook will be useful for solving Problem 2. See also the notes from today 20170602_A3_P2.nb.

Thursday, June 1, 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 20170601_A3_P4.nb.
• On Tuesday we discussed Problem 3 on Assignment 3. I almost solved this problem. See the notebook 20170530_A3_P3.nb.

Wednesday, May 31, 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.
• The notebook which is relevant to Problem 2 on Assignment 3 is Twin_Primes.nb. The methods presented in the notebook Twin_Primes.nb will be useful for solving Problem 2.
• Yesterday we discussed Problem 3 on Assignment 3. I almost solved this problem. See the notebook 20170530_A3_P3.nb for the details. Your task is to understand my solution and incorporate it to address the questions in Problem 3. I the notebook 20170530_A3_P3.nb I defined the function that calculates the radius and the central angle of a circle for which chord and arc are given. As you can see this function involves a construction of the inverse function of Sinc[] which is restricted to the domain $[0,\pi]$. Testing of anything that we define is essential. Therefore, at the end of this notebook I do test my command.
• Here is one example how not carefully programmed commands can lead to wrong results.
• One student pointed out to me that this website contains a calculator which can calculate many circle quantities. The authors of the website should be praised for their thoroughness in considering many circle quantities. However, they did not do a good job making sure that their functions work correctly.
• Consider for the circle of radius 1 and the central angle 230 degrees. Using the calculator on this website gives the chord 1.8126 and the arc 4.0143. Next use the calculator with the chord 1.8126 and the arc 4.0143 to calculate the radius and the central angle. The calculator gives some large numbers which are clearly wrong. One would expect to get the starting numbers 1 for the radius and 230 degrees for the central angle.
• Using the same numbers, that is radius 1 and the central angle 4.0143 radians in my command gives the chord 1.8126 and the arc 4.0143. But using the chord 1.8126 and the arc 4.0143 to calculate the radius and the angle gives the radius 1 and the central angle 4.0143, exactly what it should be.
• The notebook which is relevant to Problem 4 on Assignment 3 is PythagorasTree.nb. For a simpler example relevant to Problem 4 see also vonKoch_curve.nb.
• The final exam for Math 307 is scheduled for 1:00-3:00 pm on Thursday, June 8, 2017. Since this is the official class time we will meet during this time and I will help you finalize your Assignment 3 notebook.
• The due date for Assignment 3 is Thursday, June 8, 2017. I will grade Assignment 3 and assign the final grades on Friday, June 9, 2017, so that I can leave town on Saturday, June 10, 2017.

Friday, May 26, 2017

• Assignment 3 has been posted yesterday. We discussed Problem 1 today. See the file 20170526_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.

Thursday, May 25, 2017

• Today I gave an important hint for Problem 4 on Assignment 2. The relevant notebook is 20170525_A2_P4.nb.
• It was pointed out today that my request "Reproduce the second picture related to a cardioid from the Wikipedia page" in the second part of Problem 2 on Assignment 2 is not clear. I completely agree with this comment. When I placed that link in the assignment there were only two pictures at the WIkipedia cardioid page. Now they completely redone this page and put several new pictures. The picture that I had in mind is now the fifth picture. Because of this inaccuracy in the assignment you can ignore this part of the question and focus just on the cardioid and generalized cardioids. If you produce the animations identical to the animations on my website, I will give you extra credit.

Tuesday, May 23, 2017

• Yesterday and today we did Problem 4 on Assignment 2. The relevant notebook is 20170522_A2_P4.nb.
• The due date for Assignment 2 is Sunday, May 28, 2017. We will start discussing Assignment 3 on Thursday. The due date for Assignment 3 is Thursday, June 8, 2017. I will grade Assignment 3 and assign the final grades on Friday, June 9, 2017, so that I can leave town on Saturday, June 10, 2017.
• Below I is a revised list of my remarks about your homework notebooks.
• I consider this homework assignment to be an intellectual endeavor. Please treat it as such. Your homework notebook must show that you were intellectually engaged during the process of its creation.
• Your homework notebooks should be organized neatly. A notebook should start with a title cell. Individual assigned problems should be presented as sections.
• Each problem should contain sufficient amount of text, so that I can make sense of what is being presented. If I ask a specific question in a problem, then that question should be answered by a complete sentence which should be followed by a justification.
• The notebooks should be saved with all output deleted (Manu item Cell ⇾ Delete All Output).
• You should make sure that all the calculations evaluate properly. A good way to test this is to open the notebook and evaluate the entire notebook using the menu item Evaluation ⇾ Evaluate Notebook
• Here is a list of common mistakes in homework notebooks:
• Text in input cells. (Text should be put in special "text'' cells. Or if text is included in an input cell then it should be commented out in (* *).)
• Mathematica reports Null in Graphics output. (This error occurs when an empty space is included in a list of graphics objects.)
• If several students submit identical code for a particular problem, then all students with that code will receive only partial credit.
• Homework includes material which is not directly related to your solutions. There is no need to repeat the statements of the problems in your notebook. Answer all the questions and present your solutions in a "teacher friendly'' way.
• Claims not justified by mathematical arguments and/or Mathematica calculations and/or pictures.
• Answers to specific questions are not sufficiently specific.
• The names of the functions and the variables not cleared before the definition.
• There should be no empty cells in the homework.
• There should be no cells that report substantial errors.

Thursday, May 19, 2017

• We considered problems related to Problem 3 today. The relevant notebook is 20170519_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.

Thursday, May 18, 2017

• This week we are working on the problems from Assignment 2.
• We did Problem 1 on Monday. The relevant notebook is 20170515_A2_P1.nb.
• On Tuesday we worked on Problem 1. I updated the notebook created on Monday. We also worked on Problem 2. The relevant notebook is 20170516_A2_P2.nb.
• Today we continued working on Problem 2. I in fact solved the standard cycloid part of the problem. The relevant notebook is 20170518_A2_P2.nb.
• Notice that today, half-way through the class I accidentally deleted a large cell with quite a bit of code. Unfortunately I did not save my work, so I had to recreated what I did during 10-15 minutes of class. The moral of this is that you need to save your work often. In particular save your work when you have finished a large piece of code.

Saturday, May 13, 2017

• Your homework notebooks should be organized neatly. A notebook should start with a title cell. Individual assigned problems should be presented as sections.
• Each problem should contain sufficient amount of text, so that I can make sense of what is being presented. If I ask a specific question in a problem, then that question should be answered by a complete sentence which should be followed by a justification.
• The notebooks should be saved with all output deleted (Manu item Cell ⇾ Delete All Output).
• You should make sure that all the calculations evaluate properly. A good way to test this is to open your notebook and evaluate entire notebook using the menu item Evaluation ⇾ Evaluate Notebook
• Here is a list of common mistakes in homework notebooks:
• Text in input cells. (Text should be put in special "text'' cells. Or if text is included in an input cell then it should be commented out in (* *).)
• Mathematica reports Null in Graphics output. (This error occurs when an empty space is included in a list of graphics objects.)
• If several students submit identical code for a particular problem, then all students with that code will receive partial credit.
• Homework includes material which is not directly related to your solutions. There is no need to repeat the statements of the problems in your notebook. Answer all the questions and present your solutions in a "teacher friendly'' way.
• Claims not justified by mathematical arguments and/or Mathematica calculations and/or pictures.
• Answers to specific questions are not sufficiently specific.
• The names of the functions and the variables not cleared before the definition.

Friday, May 12, 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. 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 11, 2017

• We discussed Problem 4 on Assignment 1 on Tuesday. The notebook 20170509_A1_P4.nb contains this discussion. Today I helped you individually and created 20170511.nb with an example related to Problem 1.

Monday, May 8, 2017

• I made some final comments about Problem 2 on Assignment 1 today and we discussed thoroughly Problem 3 on Assignment 1. The notebook 20170508_A1_P2_P3.nb contains this discussion. We encountered the concept of Pure Function which is very important in Mathematica.

Friday, May 5, 2017

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

Thursday, May 4, 2017

• Assignment 1 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 Sunday, May 14, 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 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.
• Today in class I created the file 201700504_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.

Tuesday, May 2, 2017

• The notebooks that I created yesterday and today in class are 20170501_First_class.nb and 20170502_the_second_class.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 these files. Also, watch the movies linked on my Mathematica page.

Monday, May 1, 2017

• Mathematica part of the class starts on Monday, May 1, 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.