필터 지우기
필터 지우기

S-functions with ode45 in Matlab

조회 수: 7 (최근 30일)
Gigi Dioda
Gigi Dioda 2011년 6월 28일
Hi, all! I have a dynamical system written in an S-function and I want to simulate it in a Matlab loop. I use ode45 on the S-function and it seems to work (it runs with no errors). However it's not the result I was expecting. After that, I took the code from the S-function and plugged into a regular dx = f(t,x,u) function and when I applied ode45 to f, I got what I was looking for.
So, my question: what's wrong with applying ode45 to an S-function?

채택된 답변

Gigi Dioda
Gigi Dioda 2011년 6월 28일
Ok, I solved it by creating a new function handle to the S-function.
Smth like:
f = @(t,x,u,params)SfunctionName(t,x,u,1,params{:});
[Tk,Xk] = ode45(f, [T(k) T(k+1)], x, options, U(k), params);
Best

추가 답변 (1개)

Arnaud Miege
Arnaud Miege 2011년 6월 28일
You don't need to "apply" ode45 to an S-function since Simulink has its own solver. See Writing S-Functions in MATLAB in the documentation.
HTH,
Arnaud
  댓글 수: 1
Gigi Dioda
Gigi Dioda 2011년 6월 28일
Thanks for the answer, Arnaud. However, I want to use the S-function in Matlab, without calling sim on a block comprising the S-function. Basically, I want to use the S-function in Matlab just as a regular ode in the form dx = f(t,x,u).

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

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by