Why doesn't M2 function get called? Could somebody please explain what this error is and how to fix it?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have function for M2
function M2 =fRK4M2(M1,M2)
M1=10;
M2=0;
mu_2=10^-3;
K1= 10^-4;
K2=5*10^-4;
M2 = (K1*M1*M1)-(K2*M1*M2)-(mu_2*M2);
This is my M1 function
function M1 =fRK4M1(M1,M2,M3,O,P)
delta=50;
K1= 10^-4;
Ko=0.1;
n=3;
Oa=10;
Pa=100;
mu_1=10^-3;
K2=5*10^-4;
K3=10^-3;
gamma=75;
M1=(delta*M1*(1-(M1/gamma))-2*K1*M1*M1-M1*(K2.*M2)-((Oa-n)*K3*M1*M3)-((Pa-Oa)*Ko*M1*O)-(mu_1*M1));
And this is my main function
clc;clear;
%input for time
t(1)=0;
dt=0.1; %time interval
t=0:dt:100; %time span
%input empty array
T=zeros(length(t),1); %empty array for t
M1=zeros(length(t),1); %empty array for M1
M2=zeros(length(t),1); %empty array for M2
for j = 1:length((t))
T(j+1)=T(j)+dt;
M1(j+1)= M1(j)+1./(1+exp(-T(j)));
k1M2 = dt*fRK4M2(M2(j),M1(j));
k2M2 = dt*fRK4M2(M2(j)+k1M2/2,M1(j)+k1M2/2);
k3M2 = dt*fRK4M2(M2(j)+k2M2/2,M1(j)+k2M2/2);
k4M2 = dt*fRK4M2(M2(j)+k3M2,M1(j)+k3M2/2);
M2(j+1) = M2(j)+1/6*(k1M2+2*k2M2+2*k3M2+k4M2);
k1M1= dt*fRK4M1(M1(j),M2(j));
k2M1= dt*fRK4M1(M2(j)+k1M2/2,M1(j)+k1M1/2);
k3M1= dt*fRK4M1(M2(j)+k2M2/2,M1(j)+k2M1/2);
k4M1= dt*fRK4M1(M2(j)+k3M2/2,M1(j)+k3M1/2);
M1(j+1) = M1(j)+(1/6*(k1M1+(2*k2M1)+(2*k3M1)+k4M1));
end
the results I get are not as desired, please someone tell me my fault adn how to fix it. Thanks
2 Kommentare
Torsten
am 18 Jun. 2023
So the task of your code is to solve the system of differential equations
dM1/dt = (delta*M1*(1-(M1/gamma))-2*K1*M1*M1-M1*(K2.*M2)-((Oa-n)*K3*M1*M3)-((Pa-Oa)*Ko*M1*O)-(mu_1*M1))
dM2/dt = (K1*M1*M1)-(K2*M1*M2)-(mu_2*M2)
?
Since your code has so many errors, I suggest you use ODE45 for the solution.
Antworten (1)
Lakshya
am 17 Jun. 2023
Hi,
The code you provided initializes M1 and M2 to specific values (M1 = 10 and M2 = 0) within the fRK4M2 function, which might override the values passed as arguments. If you intend to use the passed arguments instead, you can remove those assignments from the fRK4M2 function.
Hope this helps.
15 Kommentare
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!