[Scilab-users] solve complex ode
Adrien Vogt-Schilb
vogt at centre-cired.fr
Tue Nov 27 14:03:20 CET 2012
On 26/11/2012 20:33, Rodrigo Thomas wrote:
> Hello,
>
> I'm having a problem to solve complex ordinary differential equations
> like (a simplified one):
>
> dx/dt = i*x.
>
> I tried to use:
>
> -->function xdot=f(x,t)
> -->xdot=%i*x
> -->endfunction
> -->x0=[1;0];
> -->t0=0;
> -->t=linspace(0,10,100);
> -->y=ode(x0,t0,t,f);
> -->plot(t,y)
>
> but Scilab give the plot of a constant line in x=1 and a exponential
> term (real expoent). How can I solve it?
>
> hug,
> Thomas.
>
>
Hi Thomas,
Indeed, the result of this ODE is very different than the result of the
naive one:
xx(:,1) = x0;
dt=0.1;
tt = 0:dt:10;
for i=1:size(t,"*")
xx(:,i+1) = xx(:,i)+dt*f(xx(:,i));
end
Now, the ODE help page seems to imply that ODE should be used with rela
matrixes and functions
So, the solution seems to be to write real functions, something like
function xdot =f(x)
im = x(1)
re = x(2)
dim = re
dre = -im
xdot = [dre; dim]
endfunction
hop this helps
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20121127/af78de10/attachment.htm>
More information about the users
mailing list