Is there a difference between an embedded function implementation in simulink and the m file code implementation?

I used the embedded matlab function to implement the following code:
function [y1,y2,y3] = fcn(u,t,I,d)
%#eml
Ts=0.3;
Td=I/1000-Ts;
Ca=0.48;
u=u/Ca;
y1=d*exp(-Ts/(Ca*t)) +u*Ts;
y2=y1*exp(-Td/(Ca*t));
num1=(1/3)*y1;
num2=(2/3)*y2;
y3=num1+num2;
end
I copied these lines into a regular m file and the results did not match. (with the values I=1000,u=80.5,t=4,d is the second output y2 so i only set an initial value of 60). Although i did not set an initial value in the simulink code (don't know how) but it shouldn't matter.
I do not understand why there is a difference in the results. Thanks, Hadas

Respuestas (1)

You might want to use the IC block in your feedback loop to ensure that y2=60 in Simulink at t=0.

Categorías

Más información sobre Simulink en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 5 de Abr. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by