Homework 1

Name:
Math 213 - Math with Mathematica
Due September 11, 2009 at 11:59pm.

Problem 1-1: List-related Questions

Goal: Understand how lists work.
Workbook: Work through pages 1-6.
New concepts: You will run into the commands Range, RotateLeft, Rest, Table, and TableForm
The Table command is very powerful and very important to understand.  You will be using it continually throughout this course.

Part (a)

Write two commands to create the list {1, 4, 7, 10, 13, 16, 19}, using Range on one hand and using Table on the other hand.

Part (b)

Create a variable TBL that is a list of two-element lists, where the first element ranges from 30 to 100 by fives and the second element is the square of the first element.  For example, the first three two-element lists are {30,900}, {35,1225}, and {40,1600}.

Part (c)

Use the TableForm command to output the data in TBL in a nice format.

Part (d)

Investigate the possibilities of what happens when you roll two dice.  What is their sum?  What is their product?  Use these provided nested Table commands:

AddDice=Table[Table[i+j,{i,1,6}],{j,1,6}]
MultDice = Table[Table[i*j,{i,1,6}],{j,1,6}]

Does this do what you expect?  Now use TableForm to output AddDice and MultDice in a more readable format.

Problem 1-2: Exercise 1.1, page 7

Part (a)

Include here your functions F and Survivor.

Part (b)

Complete Exercise 1.1 on page 7.  Write a paragraph explaining the patterns you see in the output of the Survivor function.

Part (c)

Use the Function command to create a new all-in-one function Survivor2 that does the same thing as Survivor but does not reference the function F, as explained on page 7.

Problem 1-3: Exercise 1.2, page 7

Part (a)

Write the program asked for in Exercise 1.2 on page 7.

Part (b)

In order to collect data, you will need to use a Table command nested inside another Table command, as shown above in Problem 1-1(d).

Part (c)

Once you have created the data, write a paragraph here explaining the patterns that you see.

Problem 1-4: Exercise 1.4, page 8

Write a paragraph explaining how you went about finding the Josephus survivor with an initial circle of 2000 people.

Problem 1-5: ListPlot

Goal : Understand how to plot lists.
Workbook : Work through pages 8-12.

Part (a)

Include here your function Survive.

Part (b)

On page 10, the book asks you to create a table that calculates how long Survivor and variants take using calculation times from n=100 to n=2000 in steps of 100.  Our machines are more powerful now, so instead, define three tables of calculation times for Survivor, Survivor2, and Survive, (naming them for later use) using calculation times n=500 to n=10000 in steps of 500.

Part (c)

Plot each list from part (b) individually using ListPlot and ListLinePlot, and include the version you think is clearer.

Part (d)

Plot all lists together using ListPlot or ListLinePlot.

Part (e)

Explain what conclusions you can draw from the plots in parts (c) and (d).

Problem 1-6: Fitting and Multiple Plots

Background

Goal : Understand how to fit curves to data and plot functions and lists independently or together.
Workbook : Work through pages 13-16.

As mentioned in class, the book was written using a previous version of Mathematica.  The newer versions have reduced the need to include packages into the program and have created additional commands to streamline function calls.  For example, instead of a PlotJoined option in ListPlot, the command ListLinePlot was created.

In particular, there is no need to first install the NumericalMath package in order to call the function PolynomialFit, as described on pages 13-14.  Instead, you should use the function Fit:

?Fit

Visit the documentation center to read more by clicking on the >>.

In order to fit a quadratic function, you will tell Mathematica that in order to find the best function, it may provide coefficients to (x^2), x, and 1.  Let us fit our square data from Problem 1-1:

POLY=Fit[TBL,{x^2,x,1},x]

Part (a)

Now fit the data in Problem 1-5 (b) to quadratic curves.  Define variables for these functions that you can use in Part (b).

Part (b)

We want to plot these functions on the same axes as the data to see if it is indeed a good fit.  You will need to use the Plot function to plot the function, and the Show function to put two graphs on the same axes.  Your answer will look something like this:  (modify to your preferences!)

P1=Plot[S1parabola,{x,0,10000}];
P2=ListPlot[S1List];
Show[P1,P2]

Problem 1-7: Exercises 1.5 & 1.6, pp. 15 & 17

Complete Exercises 1.5 and 1.6.  Also include Survivor2 in your analysis.