Represent Simulink Integrator block as Matlab Function
28 次查看(过去 30 天)
显示 更早的评论
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
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.
0 个评论
更多回答(4 个)
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
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;
Guy Rouleau
2012-12-5
This is not a good idea. The MATLAB function is not designed for this purpose.
1 个评论
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
2012-12-5
编辑:River Rock
2012-12-6
4 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!