Using Mathematica in Student Labs – Extra Credit Assignment

 

To get into Mathematica, log in to your student account.  Click on the Start menu at the bottom left hand corner of your screen (on the taskbar), and find Mathematica following the path SUU Programs q Science Applications q Mathematics q Mathematica.  After you click on it, due to the fact that it hasn’t yet been loaded onto local machines, it will take a couple of minutes before it’s ready to go.

 

Your extra credit assignment is simply this: Bring up Mathematica as instructed above and use it to type in the commands below.  Once you have done this, save your file and email it to armstrong@suu.edu for five points of EC.  All commands will be shown in bold, and should be typed (until you develop some more experience, at least) exactly as you see them, after which you hold down the Shift and Enter keys at the same time.  If you get a message asking if you want to evaluate, click that you do want to evaluate (i.e., in Traditional Form).  The first command takes a little longer time while the kernel loads, but then it is quick after that.  For many of the following commands, the palette off to the right can be used in place of long typing.

 

Under the Help menu on your Mathematica window under the Help selection (or simply press F1 at any time), there is a very helpful guide to using the program.  You probably want to check the Master Index option to find the topic of interest.

 

Defining and Plotting a Function The basic command to define a function is to write “f[x_]:=(put the function here).”

·       f[x_]:=x*Log[E^(1/2*1^2)+2]  (Log[x] on Mathematica means ln(x).)

·       f[1]

·       f[1.]

·       Plot[f[x],{x,0,3}]

 

Limits Mathematica will compute any limit that we are able to.  Let’s consider f as given above. 

·         f[x_]:=(x-Pi)/(x^2-Pi^2)

·         Limit[f[x],x->0] (The “->” is made by the - (dash) key followed by the > (greater than), or you can use the    palette that has an arrow  key.)

·         Here’s the derivative of f using the limit definition.

1.  f[x+h]      

2.  %-f[x]  (The “%” means “the previous output.”)   

3.  %/h 

4. Limit[%,h->0] 

·         Or we can do it directly:  Limit[(f[x+h]-f[x])/h, h->0].

 

Algebra  Mathematica is a powerful tool for algebraic simplification and solving

·       Define a new function g:  g[x_]:=2x^2-3x+4; Solve[g[x]==0,x]

·       Let’s try a cubic:  h[x_]:=3x^3-x^2+x+3

·       Find the roots:  Solve[h[x]==0,x].  Mathematica uses the cubic equation to give them exactly!

·       Solve[h[x]==0.,x]

·       More simplification:  t=(2+4x^2)^3 (x-1)^2 (x+2)^2//Expand  It is pretty quick

·       Now factor the current expression (it doesn’t remember that it is t):  Factor[t]

·       Expand[(x^2-3y^3+1/z^2)^6] or (x^2-3y^3+1/z^2)^6//Expand

 

 

Derivatives  Mathematica is a great tool for working max/min and concavity problems.  An example follows.

·       First, note that the limit used above computed the derivative: f'[x].  Yes—it’s the same.  Let’s see if it’s hard for Mathematica to take higher derivatives:  f''[x], f'''[x].

·       Simplify the last derivative found.  Note that this can be done after any expression that you want to try to simplify:  After the command, simply type //Simplify (that is, like f’’’[x]//Simplify).  You can also use //Together for a common denominator, //Expand for an algebraic expansion, //Apart for a partial fraction decomposition, and so on.

·       Define a new function p:   p[x_]:=(x^2-x)/(x^2-9)

·       Let’s see a picture:   Plot[p[x],{x,-5,5}]

·       p'[x]

·       If we need the critical points, then we solve for x where p’(x)=0:   Solve[p'[x]==0,x]

·       Putting a floating point number (that is, with a decimal point) gives numerical solutions instead of analytical:  Solve[p'[x]==0.,x]

·       What? About 17.5?  Let’s see a picture:  Plot[p[x],{x,-5,40}]

·       It isn’t obvious that there is a minimum occurring at about 17.5.  Let’s compare the function value there to the horizontal asymptote:  Compare p[17], p[17.4853], and Limit[p[x],x->Infinity].  It looks like a minimum, then.  To be sure, use the Second Derivative Test:  p''[17.4853].  It is positive, confirming the minimum.

·       We can do the same thing to find possible points of inflection:  Solve[p''[x]==0,x]

·       One more: pnew[x_]:=Log[x^2-2x+1]*E^(x^2-2Log[x^2-3x])

·       pnew’[x]

 

Integration  Mathematica is able to do integrals symbolically.  Below is how you would put commands in the old, longer way.  But you might notice a palette of to the side of your desktop where you can put integrals in directly without knowing the commands below.

·       Here are a couple of examples that require substitution; with the following, you may prefer to use the integral signs on the palette.  Just use the Tab key to take you from limit to limit, to integrand, to dummy variable.

Integrate[x^4 Sec[x^5] Tan[x^5], x], Integrate[Sin[x]/Sqrt[2+Cos[x]],x]

(Try this same thing using the palette off to the right ŕ)

·       You can also evaluate definite integrals:  Integrate[(2x+1)*(x^2+x-7)^4,{x,0,3}]

·       Double and triple integrals can be done as well; I would definitely use the palette for these.