next up previous
Next: Dynamical systems Up: Introduction to SCILAB Previous: Optimization

Simulation

Here we show how to compute numerically the solution of the simple differential equation dy/dt=A*y (which is eAt). First set the A matrix and compute it's exponential as a reference.

-->A=rand(3,3)
 A  =
!   0.2113249    0.3303271    0.8497452 !
!   0.7560439    0.6653811    0.6857310 !
!   0.0002211    0.6283918    0.8782165 !
-->e=expm(A)
 e  =
!   1.5445581    1.1097905    1.9212983 !
!   1.3593889    2.7770316    2.2953965 !
!   0.4594696    1.534714     3.0556979 !
Define the function to integrate
-->deff('[ydot]=f(t,y)','ydot=A*y');
Solve the ODE and compare with the reference value
-->e(:,1)-ode([1;0;0],0,1,f)
 ans  =
! - 2.792D-08 !
! - 4.217D-08 !
! - 3.237D-08 !


Scilab group