Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I pass out extra parameters using ODE23 or ODE45 from the MATLAB ODE suite?

759 views
Skip to first unread message

Mirko

unread,
Apr 15, 2010, 4:48:03 AM4/15/10
to
Hi to all.
I'm following this technical solution posted on matworks website
http://www.mathworks.com/support/solutions/en/data/1-196SD/?solution=1-196SD

In particular the last part using assignin and evalin.
My main function contains this:

global counter;
counter=1;
.
.
.
%ode calling
[time,states]=ode113(@rates,[0,final_time],[initial_conditions]);

Below the rates function
%rates function
.
.
.
fp=some calculation.....;
global counter;
assignin('base','fp',fp);
%at every step the fp variable evaluated in the rates function
%is stored in the main workspace with the same name
evalin('base','fp_array(conteggio,:)=fp;');
%to store the fp variable at every calling of %the ode I store the variable in an array
counter=counter+1;
%increment of the array position
.
.
.
end
My problem is that the fp_array I got, contains exactly twice the values of the integrated states I got from ode.
For example to obtain the rigth plot of fp_array I have to use
plot(time,fp_array(1:2:end,:));
I got what I needed but can someone help me to understand and avoid to obtain the correct fp_array?
Why do I obtain twice values for fp_array?
Thanks

Mirko

unread,
Apr 15, 2010, 4:49:04 AM4/15/10
to

Mirko

unread,
Apr 15, 2010, 4:49:04 AM4/15/10
to

sathishku...@gmail.com

unread,
Jul 31, 2013, 6:17:46 AM7/31/13
to
That is because the ODE45 has its own time steps of integration while the final output you get from ode45 (like in [t,X]=ode45(....)) is for the time span you specified in calling the function ode45. It is easier to passout the states(X in the output is the state vector). To get a non-state out of ode45 for the same timespan you specified for state vector X, refer to the following link:

http://www.mathworks.in/support/solutions/en/data/1-196SD/?solution=1-196SD

Personal suggestion: Use the first method(more efficient than using persistent variables and saving it workspace)
0 new messages