|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Solving ODEHi,
I am using lsode to solve a simple ODE on Octave 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 _______________________________________________ Help-octave mailing list Help-octave@... https://www.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Solving ODEfraud 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 -- _______________________________________________ Help-octave mailing list Help-octave@... https://www.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Solving ODEHi,
On 08/mag/08, at 01:08, fraud profile wrote: > Hi, > > I am using lsode to solve a simple ODE on Octave 2.1.72. > The ode is: > Solve: y''(t) + y(t) =0 > such that: > y(0)=3 & y(pi/2)=3 LSODE is intended for solving intial value problems, what you have is a boundary value problem. if you install the BIM package from octave-forge you can solve your equation by: Nnodes = 100; Nelements = Nnodes-1; x = linspace(0, 1, Nnodes)'; y(Nnodes, 1) = y_pihalf = 3; y(1, 1) = y_0 = 3; A = BIM1Alaplacian(x, -ones(Nelements, 1)); A += BIM1Areaction(x, ones(Nelements, 1), -ones(Nnodes, 1)); y(2:end-1) = A(2:end-1,2:end-1) \ ( - A(2:end-1, [1 end]) * [y_0; y_pihalf]); plot(x,y) c. _______________________________________________ Help-octave mailing list Help-octave@... https://www.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Solving ODEThe prolem that you describe
Solve: y''(t) + y(t) =0 such that: y(0)=3 & y(pi/2)=3 seems to be boundary value problem (BVP), not an initial conditions problem. The function lsode solves an initial conditions problem not an boundary value problem. I suggest using the odebvp package which solves a linear BVP. You can get it from octave-forge. It should work on you octave version http://octave.sourceforge.net/doc/f/lfdif.html tca _______________________________________________ Help-octave mailing list Help-octave@... https://www.cae.wisc.edu/mailman/listinfo/help-octave |
|
|
Re: Solving ODEOn 08/mag/08, at 10:43, Carlo de Falco wrote: > Hi, > > On 08/mag/08, at 01:08, fraud profile wrote: > >> Hi, >> >> I am using lsode to solve a simple ODE on Octave 2.1.72. >> The ode is: >> Solve: y''(t) + y(t) =0 >> such that: >> y(0)=3 & y(pi/2)=3 > > LSODE is intended for solving intial value problems, > what you have is a boundary value problem. > > if you install the BIM package from octave-forge you can solve your > equation by: > > Nnodes = 100; > Nelements = Nnodes-1; > x = linspace(0, 1, Nnodes)'; > y(Nnodes, 1) = y_pihalf = 3; > y(1, 1) = y_0 = 3; > > A = BIM1Alaplacian(x, -ones(Nelements, 1)); > A += BIM1Areaction(x, ones(Nelements, 1), -ones(Nnodes, 1)); sorry, to be consistent with your problem this line should be: A += BIM1Areaction(x, ones(Nelements, 1), ones(Nnodes, 1)); > y(2:end-1) = A(2:end-1,2:end-1) \ ( - A(2:end-1, [1 end]) * [y_0; > y_pihalf]); > plot(x,y) c. > _______________________________________________ Help-octave mailing list Help-octave@... https://www.cae.wisc.edu/mailman/listinfo/help-octave |
| Free Forum Powered by Nabble | Forum Help |