[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: ode45 for coupled system (2nd order ODE)
From: |
Allen.Windhorn |
Subject: |
RE: ode45 for coupled system (2nd order ODE) |
Date: |
Fri, 9 Nov 2012 19:41:39 +0000 |
Joza,
> -----Original Message-----
> From: address@hidden [mailto:help-octave-
>
> Here is my code anyway:
>
> function du = f1(t, y)
^^ this should be dy
> 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?
Well, dy1/dt IS y2, from the code above. And you are really
computing y1 AND y2 (look at the value of "y1", it is actually
octave:11> y1(1:20,:)
ans =
1.00000 0.00000
0.97534 -0.20289
0.90040 -0.40248
0.77762 -0.58699
0.61078 -0.74686
0.40903 -0.86857
0.21155 -0.93531
0.02071 -0.95863
-0.16367 -0.94481
-0.34044 -0.89700
-0.50747 -0.81692
-0.66159 -0.70529
-0.79795 -0.56192
-0.90883 -0.38565
-0.98170 -0.17496
-0.99920 0.03680
-0.96441 0.24332
-0.87976 0.44054
-0.74789 0.62101
-0.57295 0.77460 ...
where the left column is y1 and the right is y2, which is dy1/dt
for the values of time in t).
If you also needed dy2/dt, after using ode45, you could just do
dy = f1(t, y1)
if f1 would handle a matrix input. I know there's a way to do
that but I can't think what it is at the moment.
Regards,
Allen