[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Trying to solve du/dt = i*u
From: |
Thomas Shores |
Subject: |
Re: Trying to solve du/dt = i*u |
Date: |
Thu, 30 Apr 2009 23:09:33 -0500 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090320) |
The routine lsode expects a real system. The difficulty is easily
overcome. Simply separate arguments into real and imaginary parts thusly:
octave:2> u0 = [1,0] % u = 1 in real and imaginary parts
octave:3> t = linspace(0,5,10);
octave:4> function udot = f(u,t)
> udot = [-u(2),u(1)]; % this is I*u in real and imaginary parts
> end
octave:5> u = lsode('f',u0,t)
u =
1.00000 0.00000
0.84961 0.52742
0.44367 0.89619
-0.09572 0.99541
-0.60632 0.79522
-0.93455 0.35584
-0.98167 -0.19057
-0.73353 -0.67966
-0.26475 -0.96432
0.28366 -0.95892
octave:6> plot(t,u(:,1))
octave:7>hold on
octave:8>plot(t,u:,2))
This gives exactly what you expect, the real and imaginary parts of
u(t)=exp(i*t).
Thomas Shores
John B. Thoo wrote:
Hi, everyone.
As a toy problem, I'm trying to solve du/dt = i*u, where i^2 = -1.
This is what I've tried and gotten:
octave-3.0.5:1> function udot = f (u, t)
> udot = I*u;
> endfunction
octave-3.0.5:2> u0 = 1;
octave-3.0.5:3> t = linspace (0, 5, 10);
octave-3.0.5:4> u = lsode ("f", u0, t);
warning: lsode: ignoring imaginary part returned from user-supplied
function
octave-3.0.5:5> plot (t, u)
octave-3.0.5:6>
Gnuplot gives the constant graph u = 1 for t = 0..5.
What am I doing wrongly?
Eventually, I'd like to solve a system like this:
udot(1) = -i*u(3)*u(2)' - i*u(2)*u(1)';
udot(2) = -2*i*u(3)*u(1)' - i*u(1)*u(1);
udot(3) = -3*i*u(2)*u(1);
(I'm using ' for complex conjugate. Is that correct?)
Thanks for any help you can give.
---John.
_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
- Re: Trying to solve du/dt = i*u,
Thomas Shores <=
- Re: Trying to solve du/dt = i*u, John B. Thoo, 2009/05/01
- Re: Trying to solve du/dt = i*u, Carlo de Falco, 2009/05/01
- Re: Trying to solve du/dt = i*u, John B. Thoo, 2009/05/13
- Re: Trying to solve du/dt = i*u, John B. Thoo, 2009/05/13
- Re: Trying to solve du/dt = i*u, Thomas Shores, 2009/05/13
- Re: Trying to solve du/dt = i*u, John B. Thoo, 2009/05/15
- Re: Trying to solve du/dt = i*u, Francesco Potorti`, 2009/05/16