Why I get error to solve this ODE with euler method?
이전 댓글 표시
Hello, I need to solve this equation with euler method but I got error in array
This equation is:
dMn(t) dt = Kn-1M1(t)Mn-1(t) - KnM1(t)Mn(t) - μnMn(t)
and my code in MATLAB is
%Metode Euler
%dMn/dt= Kn-1*M1(t)*Mn-1(t)-Kn*M1(t)*Mn(t)-Mun*Mn(t)
clc;clear;
%initial variabel
sigma = 50;
K1 = 10^-4;
K0 = 0.1;
n = 6;
Oa = 10;
Pa = 100;
mui = 10^-3;
muo = 10^-4;
mup = 10^-5;
dt = 0.001;
t = 0:dt:100;
n = zeros(length(t),1);
M(1)= 2;
Mn = 0:6;
Kn = K1*M(t)*M(1)-K1*M(1)*M(t)-mui*M(t);
for i = 1:length(t)-1
K(i+1) = K(i)*M1(i)*Mn(i)-K(i)*M1(i)*Mn(i)-mui(i)*Mn(i) ;
end
and MY ERROR IS
Array indices must be positive integers or logical values.
댓글 수: 2
You are trying to use non-integral values (variable t) as indices to define Kn, which is not allowed.
As the error states array indices must be positive integers.
Are you trying to solve an ODE?
dt = 0.001;
t = 0:dt:100;
Kn = K1*M(t)*M(1)-K1*M(1)*M(t)-mui*M(t);
cindyawati cindyawati
2023년 4월 6일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
