Semester 1 Reference Guide

Plots

Plot[f, {x,(Subscript[x, min]), (Subscript[x, max])}]

Plot[{f1,f2}, {x,(Subscript[x, min]), (Subscript[x, max])}]

Plot[f, {x,(Subscript[x, min]), (Subscript[x, max])}, PlotLabel->"Text"]

Example

Plot[x^2,{x,-2,2}]

Plot[{x^2,x},{x,-2,2}]

Plot[{x^2,x},{x,-2,2},PlotLabel->"Plot 1"]

Text Input

Word document style text

Select ‘+‘ for a new line then then select ‘Plain text on the drop down menu’.

Text within code

Hidden text

Type text within (*these brackets*) to prevent it being ‘seen’ by the computer when code evaluates

Seen text

Text within “these” will be output as text, for example a title on a graph or units when used as part of a line of code

“Variables” text

Text within code that is not surrounded with either (*this*) or “this” will be treated as a variable by mathematica.

Example

We define a variable.

Title=3

We then plot a graph:

Plot[x,{x,0,1},PlotLabel->Title]

Plot[x,{x,0,1},PlotLabel->"Title"]

Plot[x,{x,0,1},PlotLabel-> "Title" (*with hidden comment*)]

Defining functions

We can define a function one of two ways. In both cases on the left hand side, I specify what variables I am using. If I want the function to evaluate after I have specified the values of variable1 and variable2 I use ‘ : then = ’ as below:

FuncDelay[variable1_,variable2_]:=variable1+variable2

If I want the right hand side of the function to evaluate before I specify the value of variable1 and variable2 then I simply use ‘ = ’

FuncEval[variable1_,variable2_]=variable1+variable2

Most of the time both ways work, An example of when it doesn’t is shown below.

Example

FuncDelay[x_]:=Dt[(x^2),x]

FuncDelay[3]

Compare with

FuncEval[x_]=Dt[(x^2),x]

FuncEval[3]

For further discussion see the screencast for week 7 of semester 1.

Mathematical operations

Differentiation

Dt[function[x],x]

Example

Dt[Cos[x],x]

Integration

For an indefinite integral:

Integrate[function[x],x]

For a definite integral:

Integrate[function[x],{x,xmin,xmax}]

Examples

Integrate[x^2,x]

Integrate[x^2,{x,0,1}]

Differential Equations

Form of command:

DSolve[LHS==RHS,y[x],x]

Recall, it is important to use a double equals ‘==’. If you use a single equals ‘=’ and get the following error:

Use the Remove command

Remove[y]

Initial conditions can be added:

DSolve[{LHS==RHS,cond1, cond2},y[x],x]

Example

DSolve[y''[x]==-y[x],y[x],x]

DSolve[{y''[x]==-y[x],y'[0]==1,y[0]==0},y[x],x]

Animation

Manipulate

Manipulate[f[n], {n,(Subscript[n, min]), (Subscript[n, max])}]

Manipulate[f[n], {{n,(Subscript[n, initial])},(Subscript[n, min]), (Subscript[n, max])}]

Example

Fmanipulate[k_]:=Plot[Sin[k*x],{x,0,2π}]

Manipulate[Fmanipulate[k],{k,1,5}]

Manipulate[Fmanipulate[k],{{k,3},1,5}]