How to use 'quad' function in Simulink

I designed enthalpy calculation block in Simulink with MATLAB block.
Enthalpy is time-independent varibale.
but 'quad' function is not applicable in Simulink.
I want to know time-indepndent integral methode in Simulink.
y = quad('(28.9 - x.*0.1571e-2 + (x.^2).*0.8081e-5 - (x.^3).*2.873e-9 )/28.013',298, u);

 采纳的回答

Friedrich
Friedrich 2012-10-15
编辑:Friedrich 2012-10-15
Hi,
this integral can be calaculted by hand pretty easily. So why not calaculate it by hand and putting the resulting formula into a MATLAB Function Block?
So the integral should be this:
- 2.563988148*10^(-11)*x^4 + 0.00000009615773629*x^3 - 0.0000280405526*x^2 + 1.03166387*x
So make a ML Function Block with your input u and use this formula to calculate the integral.
I created a small ML code which shows that both ways result in the same result and the approach "by brain" is a lot faster than the quad approach:
function test(u)
%used quad, use this in ML
tic
y = quad('(28.9 - x.*0.1571e-2 + (x.^2).*0.8081e-5 - (x.^3).*2.873e-9 )/28.013',298, u)
toc
%use this in a ML function block
tic
y = -2.563988148*10^(-11)*(u^4- 298^4) + 0.00000009615773629*(u^3 - 298^3) - 0.0000280405526*(u^2 - 298^2) + 1.03166387*(u - 298)
toc
E.g.:
>> test(300)
y =
2.0759
Elapsed time is 0.017596 seconds.
y =
2.0759
Elapsed time is 0.000374 seconds.

2 个评论

Thank you.
I'm totaly forgot what I did in my work.
Your insight totally rescue my hoplessenss.
Thank you again.
-2.563988148*10^(-11)*(u-298)*(u-5029.38091682482)*(u^2+1577.06185213947*u+7.99648405441749*10^6)
Approximately. But only approximately, as you only use three significant digits to represent 28.9 so the formula should really only be calculating with three significant digits.

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Simulink 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by