Working example: passing parameters to lsode - Octave

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Working example: passing parameters to lsode - Octave

Jana
An example code using "lsode" for beginners...

"Test.m" calls the function file "ODE.m"

Content of "Test.m"
----------------------

clear;
clc;

t = linspace (0, 50, 10); % Time interval for integration
y0 = [ 4; 1.1; 4 ]; % Initial condition for Y(0)
B=[77.27 8.375e-06 0.161]; % Additional fixed parameters used in ODE
funct=@(y0,t)ODE(y0,t,B); % create a function to supply to LODE
y = lsode (funct, y0, t) % Call LODE to solve


% Content of "ODE.m"
% ----------------------

function y = ODE (x, t, B)

y = zeros (3,1);

y(1) = B(1) * (x(2) - x(1)*x(2) + x(1) - B(2)*x(1)^2);
y(2) = (x(3) - x(1)*x(2) - x(2)) / B(1);
y(3) = B(3)*(x(1) - x(3));

endfunction



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Working example: passing parameters to lsode - Octave

siko1056
On 12/31/19 12:37 AM, Jana wrote:

> An example code using "lsode" for beginners...
>
> "Test.m" calls the function file "ODE.m"
>
> Content of "Test.m"
> ----------------------
>
> clear;
> clc;
>
> t = linspace (0, 50, 10); % Time interval for integration
> y0 = [ 4; 1.1; 4 ]; % Initial condition for Y(0)
> B=[77.27 8.375e-06 0.161]; % Additional fixed parameters used in ODE
> funct=@(y0,t)ODE(y0,t,B); % create a function to supply to LODE
> y = lsode (funct, y0, t) % Call LODE to solve
>
>
> % Content of "ODE.m"
> % ----------------------
>
> function y = ODE (x, t, B)
>
> y = zeros (3,1);
>
> y(1) = B(1) * (x(2) - x(1)*x(2) + x(1) - B(2)*x(1)^2);
> y(2) = (x(3) - x(1)*x(2) - x(2)) / B(1);
> y(3) = B(3)*(x(1) - x(3));
>
> endfunction
>
>


Thank you for the suggestion.  Here on the help mailing list, your idea
might get lost.  I opened a bug report [1] for you.

Best,
Kai

[1] https://savannah.gnu.org/bugs/?57508