[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Solving ODE
From: |
LUK ShunTim |
Subject: |
Re: Solving ODE |
Date: |
Thu, 08 May 2008 13:56:44 +0800 |
User-agent: |
Mozilla-Thunderbird 2.0.0.12 (X11/20080420) |
fraud profile wrote:
> Hi,
>
> I am using lsode to solve a simple ODE on Octave 2.1.72. <http://2.1.72.>
> The ode is:
> Solve: y''(t) + y(t) =0
> such that:
> y(0)=3 & y(pi/2)=3
>
> My code for this is:
>
> -------- file f.m ---------
> function xdot = f (x, t)
> xdot = zeros (2,1);
>
> xdot(1) = x(2);
> xdot(2) = -x(1);
> endfunction
> ---- end of f.m -----
>
> -------- file ode.m ---------
> l = linspace (0, pi/2, 20);
>
> y_min=[3;3];
> psi = lsode( "f", y_min, l );
>
> plot(l,psi(:,1));
> ---- end of ode.m -----
>
> I am getting correct answer with this. But lsode requires y_min which is
> actually the value of x(1) and x(2) at t=0. I have the value of x(1) at
> t=0 and t=pi/2.(I got the value of x(2) at t=0 by solving this on Matlab
> and then solved this by adding y_min=[3;3]; here). How can I use the
> given boundary conditions so that I don't need the values of x(2) to
> solve the problem.
>
> Thank you
>
Hello,
Maybe be you can google for "shooting method" if you want to use lsode
or other initial value problem solvers for a boundary value problem.
Alternatively, you can try the odebvp package from octave-forge.
Regards,
ST
--