Using ode45 Simulink - Anonymous Functions

2 visualizaciones (últimos 30 días)
rantunes
rantunes el 20 de Abr. de 2015
Respondida: Navaneeth Raman el 21 de Abr. de 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

Respuestas (1)

Navaneeth Raman
Navaneeth Raman el 21 de Abr. de 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

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by