Matlab Function Block ode45 solver Event option
显示 更早的评论
Hey everyone,
I have a big Problem with my simulink model.
I have include a Matlab function block into my model.
These function block should integrate the following differential equation.
function dfdt=df_dz_Validierung(tspan,y0)
T=453;
R=8.314;
rho_b=1100;
P_total=1;
Ac=(0.16^2*pi/4);
k_SR=6e6*exp(-77000/(R*T));
k_rWGS=4.8e8*exp(-108500/(R*T));
k_WGS=8e6*exp(-72000/(R*T));
dfadt=(k_rWGS*(P_total*(y0(3)/M_c)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))*...
(P_total*(y0(4)/M_d)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))-k_WGS*...
(P_total*(y0(2)/M_b)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))*...
(P_total*(y0(1)/M_a)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e)))*m_cat*M_a
dfbdt=(k_rWGS*(P_total*(y0(3)/M_c)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))*...
(P_total*(y0(4)/M_d)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))-k_WGS*...
(P_total*(y0(2)/M_b)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))*...
(P_total*(y0(1)/M_a)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))-k_SR*...
(P_total*(y0(5)/M_e)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))^0.6*...
(P_total*(y0(2)/M_b)/(y0(1)/M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))^0.4)*m_cat*M_b
dfcdt=(k_SR*(P_total*(y0(5)/M_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M_a+y0(2)/M_b+y0(3)/M_c+y0(4)/M_d+y0(5)/M_e))^0.4)*m_cat*M_e
dfdt=[dfadt dfbdt dfcdt dfddt dfedt];
dfdt=dfdt(:)
end
It works fine if it runs out of a matlab Skript. It determines with the Event function if dfedt gets Zero. But it doesn´t work out of my simulink model. I get this error.
To use an event function with ode45, you must enable variable sizing and dynamic memory allocation.
Function 'MATLAB Function1' (#23.86.144), line 5, column 1: "[t,y,te,ye,ie] =ode45(@df_dz_Validierung,tspan,y0,options)" Launch diagnostic report.
Can anyone help me with my Problem ?
7 个评论
Birdman
2018-3-22
Up to what size your output is going to be at most?
Benedikt Huber
2018-3-22
Benedikt Huber
2018-3-22
Birdman
2018-3-22
Can you share your model please?
Benedikt Huber
2018-3-23
Birdman
2018-3-23
I saw it but Thermolib is not found in my library. Can you share the library as well?
Benedikt Huber
2018-3-23
回答(1 个)
Birdman
2018-4-3
0 个投票
To solve this problem, do this:
Click on your MATLAB Function in your model once and while it is selected, click Ctrl+H to go to Model Explorer. There, select your model Reformer->MATLAB Function and then select your Output. On the right side, you will see Size option which is -1 by default. Change that to an upper limit which you are sure your output can not exceed it in size. For instance, 100. Then check the Variable size tickbox. Go back to your MATLAB Function page on Model Explorer and again on right side, you will see Update method already set to Inherited. Change it to Discrete and specify your sampling time accordingly. Then, click Apply at the bottom of the page and go back to your model. The problem should be solved.
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!