Clear Filters
Clear Filters

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

2 views (last 30 days)
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.

Answers (0)

Categories

Find more on Simulink 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!