필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Chinmay Sharma
Chinmay Sharma 2017년 6월 15일
댓글: Chinmay Sharma 2017년 6월 19일
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
Chinmay Sharma
Chinmay Sharma 2017년 6월 19일
I would love to hear comments on missing details in the question, if there are any.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by