>> syms x t alpha beta
Now x,t,alpha,beta can be used as variables in functions.
>> syms x t
>> g=sin(x)+x^2+exp(-x)
g =
sin(x)+x^2+exp(-x)
>> subs(g,x,t)
g =
sin(t)+t^2+exp(-t)
Type help subs to learn more about this function.
>> syms x t a b
>> g=sin(x)+x^2+exp(-x);
>> int(g,x,0,b)
(-cos(b)*exp(b)+1/3*b^3*exp(b)-1)*exp(-b)+2
>> int(g,x,a,b)
(-cos(b)*exp(b)+1/3*b^3*exp(b)-1)*exp(-b)
+(cos(a)*exp(a)-1/3*a^3*exp(a)+1)*exp (-a)
Type help int to learn how to find indefinite integrals
and learn more about this function.
>> syms x
>> f=-(xv+1)+4*exp(xv-1);
>> ezplot(f,1,5)
Type >>help ezplot to learn more about this function.
y'=f(x,y), y(x0)=y0.
Consider the initial value problem: y'=x+y, y(1)=2. Create a m-function,
say funode.m, to evaluate f(x,y)=x+y:
function f=funode(x,y);
f=x+y;
The following MatLab scripts
use ode45.m to compute a sequence of { y1, ...,
yn } where yi approximates y(xi)
for xi in [1,b] (x0=1, b is given).
>> [xv,yv]=ode45('funode',[1,b],2)
y'=f(x,y), y(x0)=y0
by Picard's Method. Recall that the Picard Method generates
a sequence of approximations: y1(x), y2(x),
.... Review your class notes on Picard's Method if it is necessary.
syms x t;
y0=2;
x0=1;
f=t+y0;
y1=int(f,t,x0,x)+y0;
f=t+subs(y1,x,t);
y2=int(f,t,x0,x)+y0;
f=t+subs(y2,x,t);
y3=int(f,t,x0,x)+y0;
f=t+subs(y3,x,t);
y4=int(f,t,x0,x)+y0;
ysol=-(x+1)+4*exp(x-1);
[tt,yy]=ode45('funode',[1,5],2);
ezplot(y1,1,5)
hold
ezplot(y2,1,5)
ezplot(y3,1,5)
ezplot(y4,1,5)
ezplot(ysol,1,5)
plot(tt,yy,'-.')
hold off
title('dy/dx=x+y, y(1)=2, Picard Method')
text(1.2, 200,'solution y=-(x+1)+4e^{(x-1)}')
text(1.2, 170,'y_1,y_2,y_3,y_4 -> solution')
text(1.2, 140,'-. y_5 obtained by ODE45')
text(4.5,150,'y')
text(4.5,110,'y_4')
text(4.5,80,'y_3')
text(4.5,50,'y_2')
text(4.5,25,'y_1')
Here is the graph: