Using ode45 Simulink - Anonymous Functions
2 views (last 30 days)
Show older comments
Hey,
I am new in Simulink and tried to migrate (with some necessary modifications) a code I made in Matlab into Simulink to have a model-based approach.
However I am having issues with the implementation of ode45. I attach a prt screen that shows the issue and I don't understand neither how to solve it. I understand that I can't have anonymous functions but I don't know how to avoid this if I have to use the ode45 function.
Someone please can help me?
Thanks, Rodrigo
0 Comments
Answers (1)
Navaneeth Raman
on 21 Apr 2015
Hi,
Anonymous functions are not supported for code generation. Create another function that defines the differential equation and call it using the function handle in the ode45 function. For example, lets say that I have defined my differential equation like this:
function dy = rigid(t,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);
end
Then use the ode45 solver function to call this function:
ode45(@rigid,timspan,initial conditions)
HTH, Navaneeth
0 Comments
See Also
Categories
Find more on Ordinary 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!