Introduction to the Mathematica 
Computing Environment

This laboratory will introduce you to several of the aspects of programming, printing results, and plotting in the Mathematica environment. You will be presented with an example of a code that performs a calculation and prints the result. You will then be asked to solve a similar problem on your own. The second part of the laboratory will introduce you to plotting with Mathematica, then combining multiple curves on one plot, and then investigate plotting a new function.

1. A Simple Calculation with Output

Consider the following problem. The radioactive decay of the element thorium is given by the equation 

                                                           (Subscript[N, f]) = (Subscript[N, i]) (e^(-λt))

where  λ=ln 2 / (Subscript[t, 1/2])  = 1.14×(10^(-8)) (s^(-1)) and (Subscript[N, f]) is the number of remaining thorium nuclei, (Subscript[N, i]) is the initial number of thorium nuclei, t is the time elapsed, and (Subscript[t, 1/2]) is  the half-life of the thorium. When t=0, (Subscript[N, f]) is equal to (Subscript[N, 0]) and no decay has occurred. As t increases the amount of thorium, (Subscript[N, f]) decreases. Below is a short code that calculates the amount of thorium remaining after a given time. Execute the code and investigate the functions of the different elements of the code. For example, what happens if you remove the ";" or the "(*" from one of the lines. Notice the use of comments and variable names that make the code readable.

Ni= 1000.0; (* Initial Amount in kg *)
time = 2000; (* Decay time in seconds. *)
lambda = 1.14*(10^(-8)); (* Decay constant in s^(-1) *)
Nf= Ni*Exp[-lambda*time];
Print["The amount left is ",Nf," kg."]

2. The Volume of a Hollow Ball

Write a program to compute the volume of the shell of a hollow ball. Clearly show the user which quantities are to be entered. Consider the example in Part 1.

3. Make a Table and Plot the Trajectory of a Falling Object

A ball is tossed from the top of the Gottwald Science Center. The height of the ball, h, as a function of time, t, is

                                                      y(t) = -(1/2)g(t^2) + (Subscript[v, iy])t + (Subscript[y, i])

where g is the acceleration of gravity, (Subscript[v, iy]) is the initial speed in the vertical direction, and (Subscript[y, i]) is the height from which the ball is thrown. We want to make a plot of this function when (Subscript[v, iy])=3.0 m/s and (Subscript[y, i]) is 10.0 m. Execute the code and investigate the functions of the different elements of the code. Note especially how functions are defined.

viy=9.0;
yi=1.0;
grav=9.8;
y[t_]:=-0.5*grav*(t^2)+viy*t+yi; (* define a function. *)
myfunc=Table[{t,y[t]},{t,0,2,0.02}]; (* make a table of data points.  Delete the semicolon to see the output. *)ListPlot[myfunc,Joined->True,PlotRange->{{0,2.5},{-0.5,6}},Frame->True,FrameLabel->{"t(s)","y(t)","",""}] (* make a plot of data. *)

4. Combining Plots.

You can make different plots that can then be shown together. Notice how each plot in the example below is defined as an object. Also note how you can change the color of the plot to make it easier to distinguish.

viy=9.0;
yi=1.0;
grav=9.8;
y[t_]:=-0.5*grav*(t^2)+viy*t+yi;
myfunc=Table[{t,y[t]},{t,0,2,0.020}];plot1=ListPlot[myfunc,Joined->True,PlotRange->{{0,2.5},{-0.5,6}},Frame->True,FrameLabel->{"t(s)","y(t)","",""}]
viy2=8.0;
yi2=1.0;
grav=9.8;
y2[t_]:=-0.5*grav*(t^2)+viy2*t+yi2;
myfunc2=Table[{t,y2[t]},{t,0,2,0.02}];
plot2=ListPlot[myfunc2,Joined->True,PlotRange->{{0,2.5},{-0.5,6}},PlotStyle->RGBColor[1,0,0],Frame->True,FrameLabel->{"t(s)","y(t)","",""}]
Show[{plot1,plot2},
Graphics[Text["Red - plot 2",{1.5,4.6},{-1,0}]],
Graphics[Text["Blue - plot 1",{1.5,5.2},{-1,0}]]
]

5. The Gaussian Density Function

The Gaussian density function is a common function in physics. It is defined by the expression

                                      y = (1/(Sqrt[2]))(e^(-(x^2)/2))                      .
                                      
Write a code that calculates the value of y at a series of points and enters the data into an array. Plot the array with ListPlot. Make another array for (y^2) and plot both curves together. Consider the examples in Parts 3-4.

6. Getting Help.

Mathematica has help included with the software. To access the help click on ‘Help’ on the menubar at the top of the window and drag down to ‘Wolfram documentation’ (Mathematica was created by a guy name Stephen Wolfram who started the company that makes it). You get a new GUI with a search box at the top where you can enter words to search.