필터 지우기
필터 지우기

Represent Simulink Integrator block as Matlab Function

조회 수: 28 (최근 30일)
River Rock
River Rock 2012년 12월 4일
댓글: Edward Rodriguez 2020년 8월 10일
Hi.
I need to implement the following behavior :
The Integrator and my_Integrator blocks have to be equivalent I/O.
How should I write the Matlab Function ?
Thanks for any reply.

채택된 답변

Ryan G
Ryan G 2012년 12월 4일
As this looks like a homework problem, I can't answer directly. However I will point you in the direction of persistent variables.

추가 답변 (4개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 7일
편집: Azzi Abdelmalek 2012년 12월 8일
I don't know why do you need this, maybe if you explain exactly what you need, there is better way
  댓글 수: 9
Azzi Abdelmalek
Azzi Abdelmalek 2012년 12월 8일
편집: Azzi Abdelmalek 2012년 12월 8일
Ok, I see, If T is constant, you must then set, in model configuration parameters your fixed step time to T, and also your step block sample time to T. In this case you don't need a clock.
function y = fcn(u)
persistent uold yold
T=0.01;
if isempty(uold)
uold=0;yold=0;
end
y = u*T+yold-(u-uold)*T/2
yold=y;uold=u;
River Rock
River Rock 2012년 12월 8일
Changing the sample time of the Step block to 0.01 removed the previous offset. Thanks

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


Guy Rouleau
Guy Rouleau 2012년 12월 5일
This is not a good idea. The MATLAB function is not designed for this purpose.
  댓글 수: 1
Edward Rodriguez
Edward Rodriguez 2020년 8월 10일
Excuse me, so, What would be a good idea to implement numerical integration methods in blocks in Simulink?

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


River Rock
River Rock 2012년 12월 5일
편집: River Rock 2012년 12월 6일
My main goal is to implement the differential equations of a physical system using a single Matlab Function. As the sums and gains were easy to represent, I couldn't find any alternative for the integration.
  댓글 수: 4
Ryan G
Ryan G 2012년 12월 5일
What you have written is close it would be more like:
y(z) = yOld+u(z)/SampleTime
You cannot use the ODE solver in the MATLAB function block.
River Rock
River Rock 2012년 12월 7일
Any idea on how to get rid of this offset ?
Code looks like:
function y = fcn(u)
%#codegen
T=0.01;
persistent yOld;
persistent uOld;
if (isempty(yOld))
yOld = 0;
end
if (isempty(uOld))
uOld = 0;
end
y = yOld + (T/2)* (u + uOld);
%y=yOld + u*T;
yOld = y;
uOld = u;

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


River Rock
River Rock 2012년 12월 5일
Can anybody suggest a better way of implementing the numerical integration ? The code has to be written inside the Matlab Function Block though.
  댓글 수: 1
Kiran Mahmood
Kiran Mahmood 2018년 10월 21일
I'm working on a similar problem. Did u find the solution ? Need help.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by