Why I get error to solve this ODE with euler method?
Show older comments
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 Comments
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
on 6 Apr 2023
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!