Discussion:
lsode can take parameters as argument, like Matlab
(too old to reply)
Tao Chen
2011-08-04 12:40:45 UTC
Permalink
I have repeated what was mentioned in the following thread and found
that lsode can take parameters as argument, just like Matlab.

http://groups.google.com/group/comp.soft-sys.octave/browse_thread/thread/de216b549a3dfef2/6864cab852d8e694?lnk=gst&q=lsode#6864cab852d8e694

For example,

---
function xdot = f (x, t, r, k)

#r = 0.25;
#k = 1.4;
a = 1.5;
b = 0.16;
c = 0.9;
d = 0.8;

xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);

endfunction
---

and

x0 = [1; 2];
t = linspace (0, 50, 200)';
r = 0.25;
k = 1.4;
fd = @(x,t)f(x,t,r,k);
x = lsode (fd, x0, t);


which worked.

Why is this not documented in Octave manual?
swagat
2017-01-05 13:05:55 UTC
Permalink
Post by Tao Chen
I have repeated what was mentioned in the following thread and found
that lsode can take parameters as argument, just like Matlab.
http://groups.google.com/group/comp.soft-sys.octave/browse_thread/thread/de216b549a3dfef2/6864cab852d8e694?lnk=gst&q=lsode#6864cab852d8e694
For example,
---
function xdot = f (x, t, r, k)
#r = 0.25;
#k = 1.4;
a = 1.5;
b = 0.16;
c = 0.9;
d = 0.8;
xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);
endfunction
---
and
x0 = [1; 2];
t = linspace (0, 50, 200)';
r = 0.25;
k = 1.4;
x = lsode (fd, x0, t);
which worked.
Why is this not documented in Octave manual?
What if the variables 'r' and 'k' are variable which are being updated by the function f itself?
s***@gmail.com
2018-06-11 01:42:15 UTC
Permalink
Post by swagat
Post by Tao Chen
I have repeated what was mentioned in the following thread and found
that lsode can take parameters as argument, just like Matlab.
http://groups.google.com/group/comp.soft-sys.octave/browse_thread/thread/de216b549a3dfef2/6864cab852d8e694?lnk=gst&q=lsode#6864cab852d8e694
For example,
---
function xdot = f (x, t, r, k)
#r = 0.25;
#k = 1.4;
a = 1.5;
b = 0.16;
c = 0.9;
d = 0.8;
xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);
endfunction
---
and
x0 = [1; 2];
t = linspace (0, 50, 200)';
r = 0.25;
k = 1.4;
x = lsode (fd, x0, t);
which worked.
Why is this not documented in Octave manual?
What if the variables 'r' and 'k' are variable which are being updated by the function f itself?
If r and k are being updated.. there would be differential equations governing their evolution.
That means they must be added to the state vector. And the dimension of the 'f' or derivative vector must be increased to account for their equations.
Loading...