Effacer les filtres
Effacer les filtres

Using ode45 Simulink - Anonymous Functions

2 vues (au cours des 30 derniers jours)
rantunes
rantunes le 20 Avr 2015
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

Réponses (1)

Navaneeth Raman
Navaneeth Raman le 21 Avr 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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by