[Metalab] OT: Matlab/Scilab/Octave Frage

Thomas Themel metalab at themel.com
Fri Dec 28 06:38:41 CET 2007


Hi,
Marius Kintel (kintel at sim.no) wrote on 2007-12-28:
> Exactly how such software packages solve differential equations  
> numerically, I don't know, but I guess you might have to specify the  
> equation on some standard form for differential equations, not in form  
> of an integral using it's own partial result.

To solve ordinary differential equations numerically, you usually have
to get them to a form where the derivatives are explicitly computed from
the "current" values. For your equation, that simply means differentiating
with respect to time so that you have 

$\frac {dQ}{dt} = \left(\frac{U-\frac{Q}{C}}{R}\right)$

In octave, it looks like this (with a variable U, so that it's not
entirely pointless to solve it numerically):

function Qdot = f(Q,t)
        U = 1.0 + .2*sin(t);
        R = 2.0;
        C = 3.0;
        Qdot = 1/R * (U-Q/C);
endfunction

tMin=0
tMax=50
nSteps=200
Q0=0

tValues = linspace(tMin,tMax,nSteps);
Qresult = lsode("f", Q0, tValues);
plot(tValues,Qresult);

ciao,
-- 
[*Thomas  Themel*] A friend of mine, when asked what he wanted from Santa
[extended contact] for Christmas, replied, "A crater the size of DC."
[info provided in]
[*message header*]	- Eric Cordian on cypherpunks



More information about the Metalab mailing list