Saturday, March 12, 2011

ode maple matlab

--------------------------------------------maple
>ode:=x=diff(f(x),x$2)+2*diff(f(x),x)+2*f(x)+1;
                      / 2      \
                      |d       |     /d      \
           ode := x = |--- f(x)| + 2 |-- f(x)| + 2 f(x) + 1
                      |  2     |     \dx     /
                      \dx      /
>ics:=f(0)=1,D(f)(0)=1;
                     ics := f(0) = 1, D(f)(0) = 1
> dsolve({ode,ics});
        f(x) = 5/2 exp(-x) sin(x) + 2 exp(-x) cos(x) - 1 + x/2
> y:=5/2*exp(-x)*sin(x)+2*exp(-x)*cos(x)-1+x/2;
         y := 5/2 exp(-x) sin(x) + 2 exp(-x) cos(x) - 1 + x/2

> plot(y, x=0..10);
----------------------------------------------------------matlab

%create g.m
%xdot(1) = y', xdot(2) = y''
%x(1) = y, x(2) = y'
%t = x
%format:
%line1: xdot(2)=x(2)*f(x)+x(1)*g(x)+k(x);
%line2: xdot(1)= x(2)
function xdot = g(t,x)
xdot(2)= -2*x(2)-2*x(1)-1+t;
xdot(1) = x(2);
xdot=xdot(:);
% To make xdot a column
>>  X0 = [1 1]'; %X0[y(0), y'(0)]
t0 = 0;
tf = 10;
options = [];
[t,y]=ode45(@g,[t0,tf],X0);
plot(t,y)


-----------------------------------------------------------maple
> ode:=diff(f(x),x$2)+2*x*diff(f(x),x)+2*f(x)+1=x;
                 / 2      \
                 |d       |       /d      \
          ode := |--- f(x)| + 2 x |-- f(x)| + 2 f(x) + 1 = x
                 |  2     |       \dx     /
                 \dx      /
> ics:=f(0)=1,D(f)(0)=1;
                     ics := f(0) = 1, D(f)(0) = 1
> dsolve({ode,ics});
                      2             1/2             2
  f(x) = -1/2 I exp(-x ) erf(x I) Pi    + 3/2 exp(-x )
                        2             2      1/2                   2
         + 1/8 (-4 exp(x ) + 2 x exp(x ) + Pi    erf(x I) I) exp(-x )

-----------------------------------------------------------matlab
%create g.m
%xdot(1) = y', xdot(2) = y''
%x(1) = y, x(2) = y'
%t = x
%format:
%line1: xdot(2)=x(2)*f(x)+x(1)*g(x)+k(x);
%line2: xdot(1)= x(2)
function xdot = g(t,x)
xdot(2)= -2*x(2)-2*x(1)*t-1+t;
xdot(1) = x(2);
xdot=xdot(:);
% To make xdot a column

>>  X0 = [1 1]';
t0 = 0;
tf = 10;
options = [];
[t,y]=ode45(@g,[t0,tf],X0);
plot(t,y)


---------------------------------------------------------maple
> ode:=x=diff(f(x),x$3)-3*diff(f(x),x$2)+3*diff(f(x),x)-f(x)+1;
>
               / 3      \     / 2      \
               |d       |     |d       |     /d      \
    ode := x = |--- f(x)| - 3 |--- f(x)| + 3 |-- f(x)| - f(x) + 1
               |  3     |     |  2     |     \dx     /
               \dx      /     \dx      /
> ics:=f(0)=0,D(f)(0)=1,D(D(f))(0)=-1;
>
                                           (2)
           ics := f(0) = 0, D(f)(0) = 1, (D   )(f)(0) = -1
> dsolve({ode,ics});
>
                                                      2
               f(x) = -2 - x + 2 exp(x) - 3/2 exp(x) x
> y:=-2-x+2*exp(x)-3/2*exp(x)*x^2;
                                                     2
                y := -2 - x + 2 exp(x) - 3/2 exp(x) x
> plot(y, x=0..10);
>

---------------------------------------------------------matlab
%create g.m
%xdot(1) = y', xdot(2) = y'', xdot(3)=y'''
%x(1) = y, x(2) = y', x(3)=y''
%t = x
%format:
%line1: xdot(2)=x(2)*f(x)+x(1)*g(x)+k(x);
%line2: xdot(1)= x(2)
function xdot = g(t,x)
xdot(3)=3*x(3)-3*x(2)+x(1)-1+t;
xdot(2)= x(3);
xdot(1) = x(2);
xdot=xdot(:);
% To make xdot a column

>> X0 = [0 1 -1]';
t0 = 0;
tf = 10;
options = [];
[t,y]=ode45(@g,[t0,tf],X0);
plot(t,y)


No comments:

Post a Comment