Using Object Properties with ODE45
Show older comments
Hi All
I'm using ODE45 with my ODEs contained in the function derivs, i.e.,
[T,Y] = ode45(@(t,y)derivs(t,y,obj),[0 10],[0 0]);
The variable obj is an object which I use to perform some logical tests within derivs, i.e.,
function dy = derivs(t,y,obj)
if (t>obj.parameter1)
% Update parameter 1
obj.parameter1 = ... %some new value
end
dy = zeros(2,1);
dy(1) = ...
dy(2) = ...
end
The logical 'if' test works for the value of obj.parameter1 that is set when I initially call the constructor for the class obj, and appears to update obj.parameter1 with a new value when I view the object at the command line. However, for all subsequent calls to derivs the logical 'if' appears to be comparing t with the initial value of obj.parameter1 (i.e. the value initialised to it at construction) rather than the updated value in the if statement.
I can't figure this out since as far as I can tell obj.parameter1 is being updated in the object, but not in the if statement (all parameters are public in the class definition). I have a similar implementation in C++, and it works fine there.
Any ideas??
Many thanks
James
Answers (1)
James Briaris
on 28 Sep 2012
Categories
Find more on Numerical Integration and Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!