Trying to solve du/dt = i*u
John B. Thoo
jthoo at yccd.edu
Fri May 1 12:37:07 CDT 2009
That's very neat. I tried it and it works! :-) But now how do I
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?)
I don't see how to index the real and imaginary parts of the
functions u(1), u(2), and u(3).
Thank again.
---John.
On Apr 30, 2009, at 9:09 PM, Thomas Shores wrote:
> 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.
More information about the Help-octave
mailing list