How to declare j in runge kutta orde 4 function? Why my output doesnt exist?
조회 수: 1 (최근 30일)
이전 댓글 표시
clc;clear;
function RK4
%input konstanta
delta=50;
K1= 10^-4;
Ko=0.1;
n=3;
Oa=10;
Pa=100;
mu_1=10^-3;
mu_2=10^-3;
mu_3=10^-3;
mu_o=10^-4;
mu_p= 10^-5;
K2=5*10^-4;
K3=10^-4;
gamma=75;
%input initial condition
M1(1)=10;
M2(1)=0;
M3(1)=0;
%input for time
t(1)=0;
dt=0.01; %time interval
t=0:dt:100; %time span
%input empty array
T=zeros(length(t)+1,1); %empty array for t
M1=zeros(length(t)+1,1); %empty array for M1
M2=zeros(length(t)+1,1); %empty array for M2
M3=zeros(length(t)+1,1); %empty array for M3
O=zeros(length(t)+1,1);
P=zeros(length(t)+1,1);
fM1=@(M1,T) M1(j+1)+(dt*(delta*M1(j+1)*(1-(M1(j+1)/gamma))-2*K1*M1(j+1)*M1(j+1)-M1(j+1)*(K2.*M2(j+1))-((Oa-n)*K3*M1(j+1)*M3(j+1))-((Pa-Oa)*Ko*M1(j+1)*O(j+1))-(mu_1*M1(j+1))));
for j = 1:length((t)-1)
%T(j+1)=T(j)+dt;
M1 =M1(j)+1./(1+exp(-T(j)));
k1M1 = dt*fM1(M1(j),dt);
k2M1 = dt*fM1(M1(j)+k1M1/2, dt+k1M1/2);
k3M1 = dt*fM1(M1(j)+k2M1/2, dt+k2M1/2);
K4M1 = dt*fM1(M1(j)+k3M1,dt+k3M1);
M1(j+1) = M1(j)+1/6*(k1M1+2*k2M1+2*k3M1+k4M1);
T(j+1)=T(j)+dt;
end
figure
plot (T,M1,'r','Linewidth',3)
xlabel('time')
ylabel('M1')
end
댓글 수: 11
Torsten
2023년 5월 20일
편집: Torsten
2023년 5월 20일
If the question would bother me, I would not answer to it.
But I'm always surprised why people like you who have very little knowledge about MATLAB don't use MATLAB's onramp training course first before trying to solve rather complicated programming tasks:
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!