Mathematica Lab 3, MA21a, 2000 Text only version
------------------------------------------------------------------------

******************
* INTEGRATION    *
******************

To compute the antiderivative of a function like x*Sin[x], try

Integrate[ x*Sin[x],x]

Many integrals can not be expressed by already defined functions
as in 

Integrate[Sqrt[Sin[x]*Sqrt[x]],x] 

Definite integrals can however be defined:

NIntegrate[Sqrt[Sin[x]*Sqrt[x]],{x,0,0.2}] 

Multiple Integrals can be done with 

NIntegrate[(1+Sin[x])*Cosh[y],{x,0,2Pi},{y,0,1}]

**************************
* DIFFERENTIAL EQUATIONS *
**************************

The next example shows how to solve differential equations

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

Mathematica sees the solutions y[x]=C1*Exp[-x] and y[x]=C2 Exp[x]
which are indeed functions, when differentiated twice give it again. 

Many differential equations do not allow close solutions. An example
is the Lorentz system in Chaos theory, where one can perform a 
numerical solution

Lorentz=NDSolve[{x'[t]==10(y[t]-x[t]),y'[t]==-x[t] z[t]+28x[t]-y[t],
z'[t]==x[t]*y[t]-8z[t]/3,x[0]==z[0]==0,y[0]==.3},{x,y,z},{t,0,40},
  MaxSteps->5000];
ParametricPlot3D[Evaluate[{x[t],y[t],z[t]}/. Lorentz],{t,0,40},
PlotPoints->5000,Axes->False, Boxed->False]   

Mathematica can also solve numerically partial differential
equations, which are a topic only at the end of this course:

s=NDSolve[{D[u[x,t],t]==D[u[x,t],{x,2}],
    u[x,0]==Sin[5*Pi*x],u[0,t]==0, u[1,t]==0},u,{x,0,1},{t,0,.01}];
Plot3D[Evaluate[u[x,t]/. s[[1]]],{t,0,.01},{x,0,1},
  AxesLabel->{"t","x","u[t,x]"}, PlotRange->{-1,1},
  PlotLabel->"Heat flow",
  PlotPoints->100,Mesh->False, Boxed->False, Background->GrayLevel[0]]; 

******************
* TAYLOR SERIES: *
******************

The 10'th Taylor approximation of a function like Sin[x] is obtained
by 

Series[Sin[x],{x,0,10}]

To plot the approximations, try

f[x_]:=Sin[x];
g[y_,n_]:=Normal[Series[f[x],{x,0,n}]] /. x->y
S[n_]:=Plot[g[y,2*n],{y,-10Pi,10Pi},PlotRange->{-5,5}]; 
S[10]


***********************************
* FINDING SOLUTIONS OF EQUATIONS: *
***********************************

Want to see the general formula for the cubic equation

Solve[a*x^3+b^x^2+c^x+d==0,x]

Numerically, you get solutions of algebraic equations
as in the following example: 

NSolve[x^3+0.4*x^2+8*x+0.4==0,x] 

You can search for roots near a point x0=1.2 with 

FindRoot[Sin[x]*x^3+0.4*x^2+8*x+0.4==0,{x,1.2}] 

Solutions to two equations for two unknowns can be found like this:

Solve[{x^2+y^2==1,x+6*y==6},{x,y}]

*******************
* DIFFERENT STUFF:*
*******************

More examples to use with Mathematica can be seen in the 
following example, showing an approximation of a fractal:

Shirp[0,{i1_,j1_}]:={Rectangle[{i1,j1}]};
Shirp[n_,{i2_,j2_}]:=Module[{s={}},Do[If[Not[u==v==2],
 s=Union[s,Shirp[n-1,{u*3^(n-1)+i2,v*3^(n-1)+j2}]]],{u,3},{v,3}];s];
Show[Graphics[Shirp[5,{0,0}]],AspectRatio->1];     

or a stellated polyhedron in 

<<Graphics`Polyhedra`;
F[0]:=Dodecahedron[]; F[n_]:=Stellate[F[n-1]];
Show[Graphics3D[F[2]],Boxed->False,Background->GrayLevel[0.0]]  

or in number theory:

FactorInteger[1111111111111111111111111111111111] 

*****************
*  EXERCICE 1:  *
*****************    

Determine the antiderivative of the function x -> (Sin[x]*x)^4 

*****************
*  EXERCICE 2:  *
***************** 

What are the solutions of the equation 
x^5+x^3+x+1=0 




