# ode45 for coupled system (2nd order ODE)

7 messages
Open this post in threaded view
|

## ode45 for coupled system (2nd order ODE)

 Hi guys. I haven't used ode45 before, so I was hoping to get some help here regarding its use. I want to solve a coupled system, namely dy2/dt = -sin(y1) and dy1/dt = y2. ode45 will solve this for me for y1 as a function of t, that's nice. But say I want to obtain (y1, dy1/dt) ... is there a nice way of doing this, or will ode45 only put out (y1, t) ?
Open this post in threaded view
|

## RE: ode45 for coupled system (2nd order ODE)

 Joza, > -----Original Message----- > From: [hidden email] [mailto:help-octave- > > Hi guys. I haven't used ode45 before, so I was hoping to get > some help here regarding its use. > > I want to solve a coupled system, namely dy2/dt = -sin(y1) and > dy1/dt = y2. > > ode45 will solve this for me for y1 as a function of t, that's > nice.  But say I want to obtain (y1, dy1/dt) ... is there a nice > way of doing this, or will ode45 only put out (y1, t) ? You have y2, which is dy1/dt.  If you need all the derivatives, you already have a function to use in ode45 like fdydt = @(t,y) [-sin(y(2); y(1)]; so your derivatives can be calculated as fdydt(t,y). I tried to use ode45 for Matlab compatibility, but had some trouble with convergence, so I have been using lsode instead.  The system you are showing here is not stiff, so ode45 should work OK, but you may want to try other methods as you get more complex problems. Regards, Allen _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## Re: ode45 for coupled system (2nd order ODE)

 In reply to this post by Joza On 9 November 2012 09:29, Joza <[hidden email]> wrote: > Hi guys. I haven't used ode45 before, so I was hoping to get some help here > regarding its use. > > I want to solve a coupled system, namely dy2/dt = -sin(y1) and dy1/dt = y2. > > ode45 will solve this for me for y1 as a function of t, that's nice. Btw, I know Matlab users are taught to use ode45 as the default ODE solver, but in Octave there is also lsode. Its interface is similar to ode45, but it can usually handle a wider class of problems. - Jordi G. H. _______________________________________________ Help-octave mailing list [hidden email] https://mailman.cae.wisc.edu/listinfo/help-octave
Open this post in threaded view
|

## RE: ode45 for coupled system (2nd order ODE)

 In reply to this post by Allen.Windhorn-2 Why would I use -sin(dy1/dt) ?The sin function only applies to y1, not its derivative?
Open this post in threaded view
|

## RE: ode45 for coupled system (2nd order ODE)

 Here is my code anyway: function du = f1(t, y)         dy = zeros(2,1);         dy(1) = y(2);         dy(2) = -sin(y(1)); end ... [t, y1] = ode45(@f1, [0, 100], [1, 0]); This solves the system for y1. But I would like to also have dy1/dt .... how can I obtain that with ode45?