I am getting this error "Index exceeds the number of array elements. Index must not exceed 1."

조회 수: 4 (최근 30일)
% this is my script code to run the function
Timerange = [0,300];
ICs = 43.4;
[Tsol,Varsol] = ode15s(@Deliverable2_ODESYSFUNCTION,Timerange,ICs);
figure
plot(Tsol,Varsol(:,1))
Title('Concentration Of Hydramere In Muscles Over Time')
xlabel('Time in mins')
yaxis('Concentration')
%this is my function code
function diffeqs=Deliverable2_ODESYSFUNCTION(t,var)
%vectors
V_s = var(1);
C_GIH = var(2);
C_L1H = var(3);
C_L2H = var(4);
C_L3H = var(5);
C_L4H = var(6);
C_CenH = var(7);
C_M = var(8);
ConcHGI = 0.3417; %Molar
%Constants
H_inAm = 43.4; %Grams
K_s = 0.045; %min^-1
Vol_GI = 2.4; %litres
Vol_L1 = 0.27; %litres
Vol_L2 = 0.27; %litres
Vol_L3 = 0.27; %litres
Vol_L4 = 0.27; %litres
Vol_CC = 11.56; %litres
Vol_Mu = 27.56; %litres
Vol_MuCC = 0.95; %litres/min
VolFr_GICC = 0.9; %litres/min
VolFr_L1GI = 0.9; %litres/min
VolFr_L1CC = 0.45; %litres/min
VolFr_L2 = 1.35; %litres/min
VolFr_L3 = 1.35; %litres/min
VolFr_L4 = 1.35; %litres/min
VolFr_CCL4 = 1.35; %litres/min
VolFr_CCMu = 0.95; %litres/min
VolFr_GI = 0.9; %litres/min
%Eqs
diffeqs(1,8) = -(K_s*V_s); %Eq1/Eq8
diffeqs(2,8) = ((VolFr_GI*(C_CenH-C_GIH)+((K_s)*(V_s)*(ConcHGI)))/Vol_GI)
end

답변 (1개)

Torsten
Torsten 2023년 11월 19일
편집: Torsten 2023년 11월 19일
You define
ICs = 43.4;
Therefore, ode15s expects that you want to solve one differential equation.
Consequently, "var" in the list of inputs to your function is one single value.
function diffeqs=Deliverable2_ODESYSFUNCTION(t,var)
But you treat it as if it were an array of eight values:
%vectors
V_s = var(1);
C_GIH = var(2);
C_L1H = var(3);
C_L2H = var(4);
C_L3H = var(5);
C_L4H = var(6);
C_CenH = var(7);
C_M = var(8);

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by