help-octave
[Top][All Lists]
Advanced

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

Re: Trying to solve du/dt = i*u


From: Carlo de Falco
Subject: Re: Trying to solve du/dt = i*u
Date: Sat, 2 May 2009 01:09:51 +0200


On 1 May 2009, at 19:37, John B. Thoo wrote:

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.



try the following:

----------8<------------
function ydot = fun(y, t)

u = y(1:3) + i * y(4:6);

ydot(1) = real(-i*u(3)*u(2)' - i*u(2)*u(1)');
ydot(2) = real(-2*i*u(3)*u(1)' - i*u(1)*u(1));
ydot(3) = real(-3*i*u(2)*u(1));

ydot(4) = imag(-i*u(3)*u(2)' - i*u(2)*u(1)');
ydot(5) = imag (-2*i*u(3)*u(1)' - i*u(1)*u(1));
ydot(6) = imag (-3*i*u(2)*u(1));

endfunction

[x, istate, msg] = lsode ('fun', ones(6,1), linspace(0,10,100))
plot(x(:,1), x(:,4), 'r', x(:,2), x(:,5), 'b', (x(:,3), x(:,6), 'k')

----------8<------------
c.









reply via email to

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