Matlab Function Block ode45 solver Event option
Show older comments
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_e)/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+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 Comments
Birdman
on 22 Mar 2018
Up to what size your output is going to be at most?
Benedikt Huber
on 22 Mar 2018
Benedikt Huber
on 22 Mar 2018
Birdman
on 22 Mar 2018
Can you share your model please?
Benedikt Huber
on 23 Mar 2018
Birdman
on 23 Mar 2018
I saw it but Thermolib is not found in my library. Can you share the library as well?
Benedikt Huber
on 23 Mar 2018
Answers (1)
Birdman
on 3 Apr 2018
0 votes
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.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!