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!