Mathematica

Initializing the kernel:

On the right hand side there are a number of brackets,  Click on the one that is beside the expression "2+2".  Then hit the return key while holding down the shift key.  This will start   up the Mathematica "kernel" or central processing program.  It may take a few seconds to respond.

2+2

In all of the below text, the red sections ask you to calculate  certain things.  They are your assignment for this lab.

Complicated expressions:

The speed of sound is about 760 mi/hr.  Below we convert this to km/sec.  Click on the 
expression and type shift-return:

(760 (mi/hr))(((1.609 km)/(1 mi)))(((1 hr)/(60 min)))(((1 min)/(60 sec)))

Now it's your turn:

(1)    The speed of light is  186,000 mi/s.  Calculate the distance  it travels in one year,   both in miles and in kilometers.   Click in the region between below this text.  When you type it will open up a new ``box''.  Enter in your formula, in a fashion similar to the one above.  When you are done, type Shift-Return.

Mathematica is a Symbolic manipulator:

Mathematica is more than just a fancy calculator.  It can  perform algebraic operations as well.  The form or "syntax"  is:

Solve[{eq1 == rhs1, eq2 == rhs2,...}, { var1, var2..}]

Note the special use of a double equals sign  (==).  This is a special ``relational'' symbol for Mathematica.   Below are three examples that we did in class.  The first is a  simple quadratic formula.  The second evaluates the same problem numerically.  The third is a system of three  equations.

Solve[{(x^2)+x-12==0},{x}]

NSolve[{(x^2)+x-12==0},{x}]

Solve[{x+y+z==1,x-y+z==2,x-y-z==3},{x,y,z}]

(2)   Solve the following cubic problem.  Obtain your answer both symbolically and numerically.:
  
                        2x^3 - 20 x^2 + 60 x - 50 = 0
                   
Plot the function, and verify that the roots Mathematica finds are correct.

Below are the equations for al 2D scattering problem,  conserving energy and momentum.     Object 1 has a mass of 10kg, and object 2 has a mass of 20kg.    Their initial velocities are 
  
                           v1x = 5 m/s        v1y = 3 m/s                         
                           v2x= -6 m/s      v2y = 8 m/s
                           
 We are also told that v3y=0 after the collision.  Mathematica will find two solutions to this   problem.  We can do no better with the information we are given.  (Why?)
 
       The NSolve evaluates the expressions numerically.  (Remove the letter N and see what a mess you get!).  The Simplify cancels out the units.  I have included them in this calculation explicitly.  It is common to drop the units entirely.

Simplify[NSolve[{(((10 kg) (5 m))/s)+(((20 kg) (-6 m))/s)==(10 kg) v3x+(20 kg) v4x,(((10 kg) (3 m))/s)+(((20 kg) (8 m))/s)==(10 kg) v3y+(20 kg) v4y,(1/2) (10 kg) ((((((5 m)/s)))^2)+(((((3 m)/s)))^2))+(1/2) (20 kg) ((((-((6 m)/s)))^2)+(((((8 m)/s)))^2))==(1/2) (10 kg) ((v3x^2)+(v3y^2))+(1/2) (20 kg) ((v4x^2)+(v4y^2)),v3y==0},{v3x,v3y,v4x,v4y}]]

(3)  Alter the above formula, replacing the condition that v3y=0 with the condition that the x  and y components of v3 are equal, and re-solve the problem.

Mathematica and Calculus

Mathematica and derivatives

Mathematica can take derivatives in a symbolic fashion.  Taking a derivative is a `function' just like taking a sine or cosine of  a number.  The difference is that the argument is not a simple   number but a function itself.  In addition, we have to tell the  program the variable we are `deriving' - are we taking a derivative  with respect to time, position or what?  The syntax of this process is:

(∂_x) f[x]      or    D[f[x], x]

(4) Take the derivative of the following functions, with respect to the variable x.

       (1)    f[x] =  x^2/(1+x^2)

       (2)   f[x]= Sqrt[x]/(1+Sqrt[x])

       (3)   f[x]= Log[Tan[x]]

Mathematica and Integration

We can also do integrals in Mathematica.    We can do  definite integrals (where
we are integrating from an initial point to a final point):

(∫_xi^xf)f[x]\[DifferentialD]x   


Integrate[f[x],{x, xi, xf}]

The first argument is the function you wish to integrate.  Then in curly brackets you list the integration variable, the upper limit,  and the lower limit of integration.  

   We can also do indefinite integrals, where we only evaluate the  integral at the upper limit, leaving it as a function of the  variable:

∫f[x]\[DifferentialD]x

Integrate[f[x],x]

(5)  Calculate the indefinite integral of the following functions:

      (a)   f(x) = x^5

      (b)  f(x) = Log[x]

      (c) f(x) = Sqrt[x^2+1]

Mathematica and Plotting

Simple 2D plots

Mathematica is great for plotting lines, curves and surfaces.   Again, the command will be a function called `Plot' (logically  enough).  It will take as arguments the function to be plotted, the dependent variable, and the range to be plotted.
 
     Here are a few fun plots:

Plot[(x^2),{x,0,4}]

Plot[(x^3)-2 (x^2)+x,{x,0,2}]

(6)  Plot the following functions over the range specified.

     (1)  f(x)= (x^2 - x + 6) / (x^2 -2x +8)    over the range -5 to 5.
     
     (2)  Plot the following  approximations to the sine function over  the range 0 to 2Pi.  Keep including more terms until you get a function that looks  like the sine over that interval.  How many terms do you have to keep?

                        f(x)= x - x^3/(3!) + x^5/(5!) - x^7/(7!) +......

(7)   Above you solved the following cubic problem.  :
  
                        2 x^3 - 20 x^2 + 60 x - 50 = 0
                   
        Plot the function, and verify that the roots Mathematica found are correct.

Simple 3D plots

Plotting in 3D isn't much harder. You just have to specify a range  of x and y values.

Plot3D[-(1/(Sqrt[(((x-1))^2)+(y^2)]))+(1/(Sqrt[(((x+1))^2)+(y^2)])),{x,-4,4},{y,-4,4},PlotPoints->30]

(8) Execute the above command and look at the resulting plot.  Now replace the word ``Plot3D'' with ``ContourPlot'', and again execute the command.  What is  this resulting plot, and how does it relate to the original plot?  (Describe it in words).

(9)  Plot an interesting function of x and y using Plot3D.  By interesting, I mean that it should have some structure, and not be a plane or a simple surface.

(10)  Look up parametric plots (in 2D) in the help browser.  Use this function to plot a spiral in 2D.  If you are feeling ambitious, try plotting a helix in 3D.  

(11)  Look up the function "Series" in the help browser.  Use this to calculate the the series expansion of the tangent function around the origin.