Computer Lab 0: Lecture 0

In our computer lab lectures we will work together through concepts and challanges we have discussed over the week in class.

Objective/Overview:

Today we are going to play around with some simple Mathematica commands.  For your take-home exercise, you will work through the first few tutorials for Mathematica.

Functions and Expressions

Let’s write a simple expression f1(x)=2*Sin[3*x].  In Mathematica this is super easy to do:

f1=2*Sin[3*x]

We can plot this in x with the Plot command:

Plot[f1,{x,0,10}]

We can change the plot, add labels, change the range...

Plot[f1,{x,0,10}, PlotRange->{-3,3}, PlotLegends->{"2Sin(3x)"},PlotLabel->"My First Plot" ]

But what if we want some flexibility?  What if we want to determine the Amplitude or Phase later on?  Then we can define a function:

f2[a_,b_]:=a*Sin[b*x]

Now, we simply have to define a and b whenever we use this function.  For example:

Plot[f2[2,3],{x,0,10}, PlotRange->{-3,3}, PlotLegends->{f2[2,3]},PlotLabel->"My First Plot" ]

We can look at how this plot changes when we change one of the parameters by creating a table:

Plot[Table[f2[a,3],{a,1,5,1}],{x,0,10}, PlotRange->{-5,5}, PlotLegends->{f2[a,3]},PlotLabel->"My First Plot"]

We could also animate this plot...let’s let a change from 0-5 and animate this...

Animate[Plot[f2[a,3],{x,0,10}, PlotRange->{-5,5}],{a,0,5,.1}]

We can design our label to show what is being plotted/animated

Animate[Plot[f2[a,3],{x,0,10}, PlotRange->{-5,5}, PlotLabel->{f2[a,3]}],{a,0,5,.1}]

Play around with plots, animation, Tables, labeling, legends, etc. for the remainder of the hour...see how pretty you can make your plots...