help-octave
[Top][All Lists]
Advanced

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

Re: function writing in differential equations


From: Carlo de Falco
Subject: Re: function writing in differential equations
Date: Tue, 14 Oct 2008 20:48:47 +0100


On 14/ott/08, at 20:27, Carlo de Falco wrote:


On 14/ott/08, at 18:52, genehacker wrote:

xdot(1) = 0.5 * exp(-10*t) - x(4) * x(1);
xdot(2) = x(5) * 0.5 - x(6) * x(2);
xdot(3) = x(6) * x(2) - 0.5 * x(3);
x(4) = 0.5- ((0.5- 0.1)/(1 + (x(1)/5)));
x(5) = 0.5- ((0.5- 0.1)/(1 + (x(1)/5)));
x(6) = 0.1-((0.1- 0.5)/(1 + (x(1)/5)));

put in this form the system is an ODE as you can eliminate x(4:6) in terms of x(1).
You can solve the system this way:

x4 = @(x1) 0.5- ((0.5- 0.1)/(1 + (x1/5)));
x5 = @(x1) 0.5- ((0.5- 0.1)/(1 + (x1/5)));
x6 = @(x1) 0.1- ((0.1- 0.5)/(1 + (x1/5)));

xdot = @(x,t) [ 0.5 * exp(-10*t) - x4(x(1)) * x(1);
             x5(x(1)) * 0.5 - x6(x(1)) * x(2);
             x6(x(1)) * x(2) - 0.5 * x(3)];

t = linspace(0,10,100);
x = lsode (xdot, zeros(3,1), t);

plot(t,x)
c.


BTW if for some reason you still wish to use DASSL (or DASPK) for solving the system above, you can do:

f = @(x,xprime,t) ( xprime - xdot(x,t));
X = daspk (f, zeros(3,1), xdot(zeros(3,1),0), t);

which of course gives the same result as you can see by doing

plot(t,x,t,X,'kx')

c.





reply via email to

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