help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Juan Pablo Carbajal
Subject: Re: ode45 for coupled system (2nd order ODE)
Date: Fri, 9 Nov 2012 18:52:02 +0100

On Fri, Nov 9, 2012 at 6:41 PM, Joza <address@hidden> wrote:
> 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?
>
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/ode45-for-coupled-system-2nd-order-ODE-tp4646324p4646344.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave

dy1/dt according to your equation is nothing but y1(,:)

If you need other derivatives, you can evaluate your f1 function.

Reocmendation:
You can write your ode/lsode functions in the following way
function du = f1(y, t)
         dy = zeros(2,size(y,2));
         dy(1,:) = y(2,:);
         dy(2,:) = -sin(y(1,:));
 end

then once you have solved your equation
[t, sol] = lsode(@f1, [0, 100], [1, 0]);

you can run
dsol = f1(sol', t)

to get all derivatives.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]