File returns a vector of length 29, but the length of initial conditions vector is 8.

조회 수: 1 (최근 30일)
function ans = final_project()
CI_CO2 = [0,10];
Y0 = [0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,4.75,0.7];
options = odeset('RelTol', 1e-10,'AbsTol',[1e-10,1e-10,1e-10]);
[CI_CO2,VA] = ode45(@respiratory_model,CI_CO2,Y0,options);
plot(CI_CO2,VA)
function res = respiratory_model(CI_CO2,VA)
MT_CO2 = 0.221; MT_O2 = 0.221; MB_CO2 = 0.042; MB_O2 = 0.042; PB = 760;
k1 = 0.107; k2 = 0.415; k3 = 0.2; k4 = 0.05; k5 = 0.92; h = 820067507;
u = -148822662; v = 9.8949e+06; p = -2.7670e+05; q = 3.3179e+03; r = 43;
f = 0.003; s = 2.3; g = 98; W = 0.014; S = 0.024; a = 99; b = 19.6;
d = 0.0008; n = 3; m = 98; Q = 6; QB = 0.7; QBN = 1;
CB_CO2 = 55.9; CB_O2 = 0.110; CA_CO2 = 5.6; CA_O2 = 14.1; CT_CO2 = 54; CT_O2 = 0.134;
CI_O2 = 0.1967;
eq58 = MB_CO2 + QB*(k1*(PB*CA_CO2)^k2) - CB_CO2;
eq59 = MT_CO2 + (Q-QB)*(k1*(PB*CA_CO2)^k2-CT_CO2);
eq60 = QB*(CB_CO2-CT_CO2) + Q*(CT_CO2-k1*(PB*CA_CO2)^k2) + VA*(CI_CO2-CA_CO2);
eq61 = -MB_O2 + k3*QB*((1-exp(-k4*k5*PB*CA_O2))^2 - (1-exp(-k4*PB*CB_O2/S))^2);
eq62 = -MT_O2 + k3*(Q-QB)*((1-exp(-k4*k5*PB*CA_O2))^2 - (1-exp(-k4*PB*CT_O2/S))^2);
eq63 = -k3*QB*((1-exp(-k4*PB*CB_O2/S))^2 - (1-exp(-k4*PB*CT_O2/S))^2) + k3*Q*((1-exp(-k4*PB*CT_O2/S))^2 - (1-exp(-k4*k5*PB*CA_O2))^2) + VA*(CI_O2-CA_O2);
eq64 = -VA + a*(CB_CO2)^(1/k2) - b + d*(m-k5*PB*CA_O2)^n;
eq65 = -QB + W*(h*(CA_CO2)^5 + u*(CA_CO2)^4 +v*(CA_CO2)^3 + p*(CA_CO2)^2 + q*CA_CO2 + r + f*(g-1/k5*(PB*CA_O2))^8) + QBN;
res = [eq58; eq59; eq60; eq61; eq62; eq63; eq64; eq65];
end
end
Keep getting this error message and can't figure out how to fix this. When I add to my initial conditions, my vector length increases as well. Any help would be greatly appreciated. Thank you!

채택된 답변

Walter Roberson
Walter Roberson 2021년 11월 27일
Y0 = [0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,4.75,0.7];
8 boundary conditions.
function res = respiratory_model(CI_CO2,VA)
inside the function, the current boundary conditions are stored in VA. You must return a column vector that has the same number of elements that VA has -- so an 8 x 1 vector.
eq60 = QB*(CB_CO2-CT_CO2) + Q*(CT_CO2-k1*(PB*CA_CO2)^k2) + VA*(CI_CO2-CA_CO2);
that computation uses all of VA, so eq60 in itself will have at least as many elements as VA has.
eq63 = -k3*QB*((1-exp(-k4*PB*CB_O2/S))^2 - (1-exp(-k4*PB*CT_O2/S))^2) + k3*Q*((1-exp(-k4*PB*CT_O2/S))^2 - (1-exp(-k4*k5*PB*CA_O2))^2) + VA*(CI_O2-CA_O2);
Also uses all of VA
eq64 = -VA + a*(CB_CO2)^(1/k2) - b + d*(m-k5*PB*CA_O2)^n;
Also uses all of VA
res = [eq58; eq59; eq60; eq61; eq62; eq63; eq64; eq65];
Since res includes three items each of which has as many items as VA has, then the size of res will be 3 times the size of VA, plus the length of the entries that are scalars. 5 scalar entries + 3 * 8 = 29 returned elements.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by