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!
