Mathematica Basics for HW#1

Below are a few simple commands that will come in useful in some of your homeworks.  Notice a few basics:
	-All commancs start with a capital letter and use the square brackets [ ].
	-Variables start with lower case.
	-Anytime you want a brief description of a command just use the ?CommandName function. (see below)  Two ??s gives even more info.
	-Becareful about your variables.  They stay set forever unless you explicitly change them or use the Clear[variable] command.
		
Work through the following in a Mathematica session and see what you get.  Mathematica should be available in any student computer lab. Turn in printouts of your work.

First, quick and easy plotting.  Here's an example,  but feel free to play with different functions.

?Plot

Plot[Sin[x], {x, 0, 2*Pi}]

Notice that Pi is a "command".  If you don't believe me...numerically evaluate it to...hmm... let's say....67 digits.

N[Pi, 67]

While we're at it...how about e, too!

N[E, 67]

We'll be solving lots of differential equations in this class.  Mathematica can solve them too using DSolve, so this gives you a way to check your math on your homework!

?DSolve

The expression below solves the simple equation (((d^2) y)/(dx^2))=2, with boundary conditions, (Subscript[([(dy/dx)]), 0])=0 and y[0]=0

DSolve[{y''[x] == 2, y'[0] == 0, y[0] == 4}, y[x], x]

Some differential equations will not be easily solvable, so we'll want to use numerical techniques.  NDSolve is Mathematica's numerical solver.

?NDSolve

solution  =  
      NDSolve[{y''[x] == 2, y'[0] == 0, y[0] == 4}, 
        y[x], {x, 0, 2}]

Notice that you don't have an answer; it's imbedded in a list of numbers not shown.  The best way to look at the solution is a plot.  We use the variable solution so that Plot knows what list of numbers to plot.  Also, that weird "/." sign below tells the Evaluate command to look in solution for the list of y[x] values.  The PlotRange command gives the y-axis range.  Try the plot with and without the PlotRange command.

Plot[Evaluate[y[x]  /.  solution], {x, 0, 2},  PlotRange -> {0, 8}]

Does the plot look like it should?
These DiffyQ solvers can also solve coupled differential equations.  You can try it if you want; you'll be a leg up on next week's homework......

Below is an example of solving coupled Differential Equations.

\(ClearAll[]; 

    solution2\  = \ 
      NDSolve[{\(\(y'\)'\)[x] == 2 + \(z'\)[x], 
          \(\(z'\)'\)[x] == 3 + 5*\(y'\)[x], 
          \(y'\)[0] == \(z'\)[0] == z[0] == 0, y[0] == 4}, {y, z}, {x, 0, 2}]
        \)

Now to see y and z functions, we can either plot them versus each other (a Parametric plot)..

ParametricPlot[Evaluate[{y[x], z[x]}  /.  solution2], {x, 0, 2}]

....Or...we can overlay to plots of y vs. x and z vs. x....

\(Show[Plot[Evaluate[y[x]\  /. \ solution2], {x, 0, 2}], 
	
      Plot[Evaluate[z[x]\  /. \ solution2], {x, 0, 2}]]\)

When you are ready to print the whole thing out, please do the following to minimize paper usage
•Go back through the document and clean things up, like deleting unnecessary returns, trial runs, and pesky messages about variables being named like other variables, etc...
•Then click on Format on the Toolbar and choose Printing Style Environment -> Printout.
•Under File click Printing Settings -> Page Setup and make sure you're set for Portrait.
•Now under File click Print.  In the print dialog box choose the Layout tab and select 2 pages per sheet.
•Click Print.