[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Octave code for y'''=0 ODE
From: |
Tatsuro MATSUOKA |
Subject: |
Re: Octave code for y'''=0 ODE |
Date: |
Tue, 28 Jul 2015 19:22:33 +0900 (JST) |
----- Original Message -----
> From: deepus
> To: help-octave
> Cc:
> Date: 2015/7/28, Tue 17:51
> Subject: Re: Octave code for y'''=0 ODE
>
> How can I write in this format
>
> /function ret=f(x,t); ret=2*t^2; end;
> x=lsode('f',3,(t=linspace(0,3,4)));
> #plot(t,x)
> x/
>
DAS has shown the symbolic solution but I assume your final goal is solve ODE
which cannot solve symbolic way.
First ODE solver is in general not applicable higher order ODE like
y'''+4y''+5y'+2y=0 % ODE
y(0)=5, y'(0)=8, y''(0)=16 % initial condition
Analytical solution is
y(t)=2texp(-t)+5exp(-2t)
However, general ode solver can solve the first order simultaneous ODE.
As was written, you should reduce you problem to higher order ODE
to the first order simultaneous ODE.
In the above case, a equivalent set of the first order simultaneous ODE is
y1'=y2
y2'=y3
y3'=-4y3-5y2-2y1
and initial condition
y1(0)=5, y2(0)=8, y3(0)=16
Solution of y1 is the same solution of y'''+4y''+5y'+2y=0
If you do not know anonymous function, please see the manual.
Of course, you can define function
function ... endfunction
% script
% define of function using anonymous fucntion
% the point is that return value should be a vector.
f=@(y,t)[y(2);
y(3);
-4*y(3)-5*y(2)-2*y(1)];
y0=[5 -8 16]; % initial condition
t=0:0.1:4; % vector of independent valuable
y=lsode(f, y0, t); % solve ODE
plot (t, y(:,1),'@', t, [2*t.*exp(-t)+5*exp(-2*t)]); % plot solutions by lsode
and analytical one.
print exam.png % save graph
% end of script
graph is attached.
Note that y(:,1) is solution vector of y'''+4y''+5y'+2y=0, y1(0)=5, y2(0)=8,
y3(0)=16
However, the ODE you have shown is not simple initial ODE problem.
Initial conditions are given in different t like y(0)=1, y'(1)=1, y''(2)=3.
This problem is not be solved in simple way using usual ode solver.
Tatsuro
exam.png
Description: PNG image