MATH52808/24/2018
TeXmacs is an editor especially well suited for scientific work:
Mathematical text is easily written, in legible form, e.g. is a differential equation and
(1) |
is an initial value problem.
The text can be exported to LaTeX, HTML, PDF formats.
Computations can be interspersed, such that one obtains a “living” document that contains the code used to produce results.
Mathematica solution of the ODE
In[1]:=
ODE = y'[x]==x+y[x]
In[2]:=
DSolve[ODE,y[x],x]
In[3]:=
Mathematica is a computational platform that combines symbolic, numerical and graphical calculations. Sample computations:
In[3]:=
10!
In[5]:=
p4=Expand[(x+y)^4]
In[6]:=
Factor[p4]
In[8]:=
Integrate[1/(1+x^2),x]
In[10]:=
LaplaceTransform[Sin[t],t,s]
In[13]:=
FourierTransform[Exp[-x^2],x,k]
In[14]:=
An analytical solution to an ODE may be impossible. This usually happens for non-linear, higher-order ODEs, e.g.,
In[7]:=
ODE = y”[x] + x y[x] y'[x] == 0
In[8]:=
DSolve[ODE,y[x],x]
Even if an analytical solution is obtainable, it might be too complicated to work with
In[24]:=
f[x_,y_] = (x+y)^5;
ODE = y'[x] == f[x,y[x]]
In[25]:=
DSolve[ODE,y[x],x]
In[26]:=
In such cases an approximation may be obtained numerically. Software systems like Mathematica contain sophisticated procedures that combine multiple algorithms to find a solution
In[42]:=
IniCond = y[0]==0
In[43]:=
Y[x_] = y[x] /.
NDSolve[{ODE,IniCond},y[x],{x,0,1}][[1,1]];
YN = Table[{x,Y[x]},{x,0,1,0.2}]
In[44]:=
The simplest numerical algorithm to approximate an ODE is solution is Euler's method
where , is the step size, and . Euler's method is applied repeatedly within a loop to obtain the approximation
In[29]:=
h=0.2; x0=0.; y0=0.; xfinal=1.;
nsteps=Floor[(xfinal-x0)/h]
In[45]:=
YE = {y0,0,0,0,0,0};
For[i=1, i<=nsteps, i++,
YE[[i+1]] = YE[[i]] + h f[x0 + i h, YE[[i]]]
];
{YN,YE}
In[46]:=
Note that the approximate values from Euler's method are not the same as those from the Mathematica built-in NDSolve. In this lab we'll investigate why this happens.