Effacer les filtres
Effacer les filtres

How to write an odefunction in Simulink which takes input from Simulink?

2 vues (au cours des 30 derniers jours)
Chinmay Sharma
Chinmay Sharma le 15 Juin 2017
Commenté : Chinmay Sharma le 19 Juin 2017
Hello,
I am having trouble using ode15s in simulink. I require to define an odefunction which involves parameters transferred from another simulink block. If I write(a,b,c are the parameters computed in another block and used as input to this block)
fun=@(t,y)(a*y^2+b*y+c)
I get an error regarding invalid use of anonymous function in code generation.So I created an external function 'fun.m' and using 'coder.extrinsic('fun') in Simulink. It goes as
function dy=fun(t,y)
dy=a*y^2+b*y+c
end
The problem is, I cannot input a,b and c here. If instead, I modify the function to take a,b,c as input i.e.,
function dy=fun(t,y,a,b,c)
I wont be able to write this function directly. I also tried this
function dy=fun(a,b,c)
dy=@(t,y)(a*y^2+b*y+c);
end
And then in Simulink
func=fun(A,B,C)
ts=[0 10]
ode15s(func,ts,0);
But then again I get the error of invalid anonymous function in code generation.
I am confused.Any possible solution/workaround will be greatly appreciated.
Thanks.
P.S.: I am not using 2016b which allows anonymous functions in code generation. Also, the above code is purely an illustration of the actual one.
  1 commentaire
Chinmay Sharma
Chinmay Sharma le 19 Juin 2017
I would love to hear comments on missing details in the question, if there are any.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by