[Scilab-users] Fwd: Help modeling ODE system

A Khorshidi akhorshidi at live.com
Sun Sep 14 14:04:40 CEST 2014


Farid Afandiyev wrote
> It looks like this
> dV1/dt = 0.01V1 - 0.01V2
> dV2/dt = -0.01V1 + 0.01V2
> V1(0) = 10000
> V2(0) = 5000
> 
> I want to plot V1 and V2 against time t=[0:10]

Hi; 

You can use the scheme below to solve system of ODEs in Scilab: 
//
function xdot = modelName(t,x)
    xdot = f(t,x) // where xdot and x are vectors
endfunction

x0 = [x1(0) x2(0)... xn(0)]' // a vector of the initial conditions 
t0 = initialTime // a scalar: initial time
tf = finalTime // a scalar: final time
t = linspace(t0, tf)// a vector: the times that you want a solution for

x = ode(x0,t0,t,modelName);

plot(t', [x(1,:); x(2,:); ... x($,:)]')
//

And to really answer your question: 

function Vdot=model(t, V)
    Vdot(1) = 0.01*V(1) - 0.01*V(2)
    Vdot(2) = -0.01*V(1) + 0.01*V(2)
endfunction
V0=[10000 5000]';
t0=0;
t=0:0.1:10;
V = ode(V0,t0,t,model);
plot(t', [V(1,:); V(2,:)]')

HTH
Mehran
_




--
View this message in context: http://mailinglists.scilab.org/Scilab-users-Fwd-Help-modeling-ODE-system-tp4031148p4031151.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.



More information about the users mailing list