Represent Simulink Integrator block as Matlab Function
Mostrar comentarios más antiguos
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.
2 comentarios
Azzi Abdelmalek
el 4 de Dic. de 2012
What is your goal?
River Rock
el 5 de Dic. de 2012
Respuesta aceptada
Más respuestas (4)
Azzi Abdelmalek
el 7 de Dic. de 2012
Editada: Azzi Abdelmalek
el 8 de Dic. de 2012
2 votos
I don't know why do you need this, maybe if you explain exactly what you need, there is better way
9 comentarios
River Rock
el 8 de Dic. de 2012
Azzi Abdelmalek
el 8 de Dic. de 2012
Editada: Azzi Abdelmalek
el 8 de Dic. de 2012
You can't do it
River Rock
el 8 de Dic. de 2012
Azzi Abdelmalek
el 8 de Dic. de 2012
What about time t?
Azzi Abdelmalek
el 8 de Dic. de 2012
Can you post the solution?
Azzi Abdelmalek
el 8 de Dic. de 2012
Editada: Azzi Abdelmalek
el 8 de Dic. de 2012
It works with Ryan's hint, but you still need a clock as an input.
River Rock
el 8 de Dic. de 2012
Editada: River Rock
el 8 de Dic. de 2012
Azzi Abdelmalek
el 8 de Dic. de 2012
Editada: Azzi Abdelmalek
el 8 de Dic. de 2012
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
el 8 de Dic. de 2012
Guy Rouleau
el 5 de Dic. de 2012
0 votos
This is not a good idea. The MATLAB function is not designed for this purpose.
1 comentario
Edward Rodriguez
el 10 de Ag. de 2020
Excuse me, so, What would be a good idea to implement numerical integration methods in blocks in Simulink?
River Rock
el 5 de Dic. de 2012
Editada: River Rock
el 6 de Dic. de 2012
0 votos
4 comentarios
Ryan G
el 5 de Dic. de 2012
Why do you need to use MATLAB over SL blocks? Look into the persistent variables, it will get the job done, although as Guy mentioned, it's not the best way to do it.
River Rock
el 5 de Dic. de 2012
Ryan G
el 5 de Dic. de 2012
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
el 7 de Dic. de 2012
River Rock
el 5 de Dic. de 2012
0 votos
1 comentario
Kiran Mahmood
el 21 de Oct. de 2018
I'm working on a similar problem. Did u find the solution ? Need help.
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!