Can graphs in Matlab provide a more detailed scale?
4 views (last 30 days)
Show older comments
cindyawati cindyawati
on 19 Jul 2023
Answered: Steven Lord
on 19 Jul 2023
I have 2 different function and I want to combine the plot. In Matlab cannot show the difference plot of 2 function but in excel can show the difference. How to solve that?
This is the function that has been combined
clc;clear;
%input parameter
delta=50;
gamma=75;
K1=10^-4;
K2=5*10^-4;
K3=10^-3;
K4=5*10^-3;
K5=10^-2;
K6=5*10^-2;
Ko=0.1;
n=6;
Oa=10;
Pa=100;
mu_1=10^-3;
mu_2=10^-3;
mu_3=10^-3;
mu_4=10^-3;
mu_5=10^-3;
mu_6=10^-3;
mu_o=10^-4;
mu_p= 10^-5;
%komponen paper 1
Mg = 0.047;
lambdaMf = 2*10^-1;
Fo = 3.36*10^-5;
KFo = 2.58*10^-5;
lambdaMa = 2.3*10^-1;
Ao = 0.14;
KAo = 10^-2;
beta = 10;
epsilon1 = 0.3333;
epsilon2 = 0.8;
lambdaM1Tb = 6*10^-1;
Tb=10^-2;
KTb = 2.5*10^-3;
makro1 = 0.02;
makro2 = 0.02;
dM1= 0.015;
dM2= 0.015;
dtmakro1 = (Mg*(lambdaMf*(Fo/(Fo+KFo))+lambdaMa*(Ao/(Ao+KAo)))*(epsilon1*beta/(beta*(epsilon1+epsilon2)))*makro1)+(lambdaM1Tb*(Tb/(Tb+KTb))*makro1)-dM1*makro1;
dtmakro2 = (Mg*(lambdaMf*(Fo/(Fo+KFo))+lambdaMa*(Ao/(Ao+KAo)))*(epsilon2/(beta*(epsilon1+epsilon2)))*makro2)+(lambdaM1Tb*(Tb/(Tb+KTb))*makro1)-dM2*makro2;
%input initial condition
M1(1)=10;
M2(1)=0;
M3(1)=0;
M4(1)=0;
M5(1)=0;
M6(1)=0;
O(1)=0;
P(1)=0;
M12(1)=10;
M22(1)=0;
M32(1)=0;
M42(1)=0;
M52(1)=0;
M62(1)=0;
O2(1)=0;
P2(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
M4=zeros(length(t)+1,1); %empty array for M4
M5=zeros(length(t)+1,1); %empty array for M5
M6=zeros(length(t)+1,1); %empty array for M6
O=zeros(length(t)+1,1);
P=zeros(length(t)+1,1);
M12=zeros(length(t)+1,1); %empty array for M1
M22=zeros(length(t)+1,1); %empty array for M2
M32=zeros(length(t)+1,1); %empty array for M3
M42=zeros(length(t)+1,1); %empty array for M4
M52=zeros(length(t)+1,1); %empty array for M5
M62=zeros(length(t)+1,1); %empty array for M6
O2=zeros(length(t)+1,1);
P2=zeros(length(t)+1,1);
sumter=K2*M2+K3*M3+K4*M4+K5*M5;
for j = 1:length(t)
T(j+1)=T(j)+dt;
M1(j+1)=M1(j)+1./(1+exp(-T(j)));
M1(j+1) = M1(j)+(dt*(delta*M1(j+1)*(1-(M1(j+1)/gamma))-2*K1*M1(j+1)*M1(j+1)-M1(j+1)*sumter(j+1))-((Oa-n)*K6*M1(j+1)*M6(j+1))-((Pa-Oa)*Ko*M1(j+1)*O(j+1))-(mu_1*M1(j+1)));
M2(j+1) = M2(j)+(dt*(K1*M1(j)*M1(j)-K2*M1(j)*M2(j))-(mu_2*M2(j+1))-dtmakro1+dtmakro2);
M3(j+1) = M3(j)+(dt*(K2*M1(j)*M2(j)-K3*M1(j)*M3(j))-mu_3*M3(j));
M4(j+1) = M4(j)+(dt*(K3*M1(j)*M3(j)-K4*M1(j)*M4(j))-mu_4*M4(j));
M5(j+1) = M5(j)+(dt*(K4*M1(j)*M4(j)-K5*M1(j)*M5(j))-mu_5*M5(j));
M6(j+1) = M6(j)+(dt*(K5*M1(j)*M5(j)-K6*M1(j)*M6(j))-mu_6*M6(j));
O(j+1) = O(j)+(dt*(K6*M1(j)*M6(j)-Ko*M1(j)*O(j)-mu_o*O(j)));
P(j+1) = P(j)+(dt*(Ko*M1(j)*O(j)-mu_p*P(j)));
M12(j+1) = M12(j)+(dt*(delta*M12(j+1)*(1-(M12(j+1)/gamma))-2*K1*M12(j+1)*M12(j+1)-M12(j+1)*sumter(j+1))-((Oa-n)*K6*M12(j+1)*M62(j+1))-((Pa-Oa)*Ko*M12(j+1)*O2(j+1))-(mu_1*M12(j+1)));
M22(j+1) = M22(j)+(dt*(K1*M12(j)*M12(j)-K2*M12(j)*M22(j))-(mu_2*M22(j+1)));
M32(j+1) = M32(j)+(dt*(K2*M12(j)*M22(j)-K3*M12(j)*M32(j))-mu_3*M32(j));
M42(j+1) = M42(j)+(dt*(K3*M12(j)*M32(j)-K4*M12(j)*M42(j))-mu_4*M42(j));
M52(j+1) = M52(j)+(dt*(K4*M12(j)*M42(j)-K5*M12(j)*M52(j))-mu_5*M52(j));
M62(j+1) = M62(j)+(dt*(K5*M12(j)*M52(j)-K6*M12(j)*M62(j))-mu_6*M62(j));
O2(j+1) = O2(j)+(dt*(K6*M12(j)*M62(j)-Ko*M12(j)*O2(j)-mu_o*O2(j)));
P2(j+1) = P2(j)+(dt*(Ko*M12(j)*O2(j)-mu_p*P2(j)));
end
%figure
%subplot (3,1,1)
figure
%hold on
plot(T,M1,'r', T,M12,'b','Linewidth',2)
legend ('M1', 'M12');
xlabel('time (days)')
ylabel('M1 (gr/ml)')
%subplot (3,1,2)
figure
%hold on
plot(T,M2,'b',T,M22,'r','Linewidth',2)
legend ('M2', 'M22');
xlabel('time (days)')
ylabel('M2 (gr/ml)')
%subplot (3,1,3)
figure
%hold on
plot(T,M3,'g',T,M32,'b','Linewidth',2)
legend ('M3', 'M32');
xlabel('time (days)')
ylabel('M3 (gr/ml)')
%subplot (2,1,2)
figure
%hold on
plot(T,M4,'m',T,M42,'g','Linewidth',2)
legend ('M4', 'M42');
xlabel('time (days)')
ylabel('M4 (gr/ml)')
%subplot (2,1,1)
figure
%hold on
plot(T,M5,'k',T,M52,'g','Linewidth',2)
legend ('M5', 'M52');
xlabel('time (days)')
ylabel('M5 (gr/ml)')
figure
%hold on
plot(T,M6,'m',T,M62,'g','Linewidth',2)
legend ('M6', 'M62');
xlabel('time (days)')
ylabel('M6 (gr/ml)')
%subplot (2,1,1)
figure
%hold on
plot(T,O,'k',T,O2,'g','Linewidth',2)
legend ('O', 'O2');
xlabel('time (days)')
ylabel('O (gr/ml)')
figure
%hold on
plot(T,P,'m',T,P2,'g','Linewidth',2)
legend ('P', 'P2');
xlabel('time (days)')
ylabel('P (gr/ml)')
0 Comments
Accepted Answer
Steven Lord
on 19 Jul 2023
Let's look at the data you used to create your first graph as I suspect the insights we gain from that will apply to the others as well.
clc;clear;
%input parameter
delta=50;
gamma=75;
K1=10^-4;
K2=5*10^-4;
K3=10^-3;
K4=5*10^-3;
K5=10^-2;
K6=5*10^-2;
Ko=0.1;
n=6;
Oa=10;
Pa=100;
mu_1=10^-3;
mu_2=10^-3;
mu_3=10^-3;
mu_4=10^-3;
mu_5=10^-3;
mu_6=10^-3;
mu_o=10^-4;
mu_p= 10^-5;
%komponen paper 1
Mg = 0.047;
lambdaMf = 2*10^-1;
Fo = 3.36*10^-5;
KFo = 2.58*10^-5;
lambdaMa = 2.3*10^-1;
Ao = 0.14;
KAo = 10^-2;
beta = 10;
epsilon1 = 0.3333;
epsilon2 = 0.8;
lambdaM1Tb = 6*10^-1;
Tb=10^-2;
KTb = 2.5*10^-3;
makro1 = 0.02;
makro2 = 0.02;
dM1= 0.015;
dM2= 0.015;
dtmakro1 = (Mg*(lambdaMf*(Fo/(Fo+KFo))+lambdaMa*(Ao/(Ao+KAo)))*(epsilon1*beta/(beta*(epsilon1+epsilon2)))*makro1)+(lambdaM1Tb*(Tb/(Tb+KTb))*makro1)-dM1*makro1;
dtmakro2 = (Mg*(lambdaMf*(Fo/(Fo+KFo))+lambdaMa*(Ao/(Ao+KAo)))*(epsilon2/(beta*(epsilon1+epsilon2)))*makro2)+(lambdaM1Tb*(Tb/(Tb+KTb))*makro1)-dM2*makro2;
%input initial condition
M1(1)=10;
M2(1)=0;
M3(1)=0;
M4(1)=0;
M5(1)=0;
M6(1)=0;
O(1)=0;
P(1)=0;
M12(1)=10;
M22(1)=0;
M32(1)=0;
M42(1)=0;
M52(1)=0;
M62(1)=0;
O2(1)=0;
P2(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
M4=zeros(length(t)+1,1); %empty array for M4
M5=zeros(length(t)+1,1); %empty array for M5
M6=zeros(length(t)+1,1); %empty array for M6
O=zeros(length(t)+1,1);
P=zeros(length(t)+1,1);
M12=zeros(length(t)+1,1); %empty array for M1
M22=zeros(length(t)+1,1); %empty array for M2
M32=zeros(length(t)+1,1); %empty array for M3
M42=zeros(length(t)+1,1); %empty array for M4
M52=zeros(length(t)+1,1); %empty array for M5
M62=zeros(length(t)+1,1); %empty array for M6
O2=zeros(length(t)+1,1);
P2=zeros(length(t)+1,1);
sumter=K2*M2+K3*M3+K4*M4+K5*M5;
for j = 1:length(t)
T(j+1)=T(j)+dt;
M1(j+1)=M1(j)+1./(1+exp(-T(j)));
M1(j+1) = M1(j)+(dt*(delta*M1(j+1)*(1-(M1(j+1)/gamma))-2*K1*M1(j+1)*M1(j+1)-M1(j+1)*sumter(j+1))-((Oa-n)*K6*M1(j+1)*M6(j+1))-((Pa-Oa)*Ko*M1(j+1)*O(j+1))-(mu_1*M1(j+1)));
M2(j+1) = M2(j)+(dt*(K1*M1(j)*M1(j)-K2*M1(j)*M2(j))-(mu_2*M2(j+1))-dtmakro1+dtmakro2);
M3(j+1) = M3(j)+(dt*(K2*M1(j)*M2(j)-K3*M1(j)*M3(j))-mu_3*M3(j));
M4(j+1) = M4(j)+(dt*(K3*M1(j)*M3(j)-K4*M1(j)*M4(j))-mu_4*M4(j));
M5(j+1) = M5(j)+(dt*(K4*M1(j)*M4(j)-K5*M1(j)*M5(j))-mu_5*M5(j));
M6(j+1) = M6(j)+(dt*(K5*M1(j)*M5(j)-K6*M1(j)*M6(j))-mu_6*M6(j));
O(j+1) = O(j)+(dt*(K6*M1(j)*M6(j)-Ko*M1(j)*O(j)-mu_o*O(j)));
P(j+1) = P(j)+(dt*(Ko*M1(j)*O(j)-mu_p*P(j)));
M12(j+1) = M12(j)+(dt*(delta*M12(j+1)*(1-(M12(j+1)/gamma))-2*K1*M12(j+1)*M12(j+1)-M12(j+1)*sumter(j+1))-((Oa-n)*K6*M12(j+1)*M62(j+1))-((Pa-Oa)*Ko*M12(j+1)*O2(j+1))-(mu_1*M12(j+1)));
M22(j+1) = M22(j)+(dt*(K1*M12(j)*M12(j)-K2*M12(j)*M22(j))-(mu_2*M22(j+1)));
M32(j+1) = M32(j)+(dt*(K2*M12(j)*M22(j)-K3*M12(j)*M32(j))-mu_3*M32(j));
M42(j+1) = M42(j)+(dt*(K3*M12(j)*M32(j)-K4*M12(j)*M42(j))-mu_4*M42(j));
M52(j+1) = M52(j)+(dt*(K4*M12(j)*M42(j)-K5*M12(j)*M52(j))-mu_5*M52(j));
M62(j+1) = M62(j)+(dt*(K5*M12(j)*M52(j)-K6*M12(j)*M62(j))-mu_6*M62(j));
O2(j+1) = O2(j)+(dt*(K6*M12(j)*M62(j)-Ko*M12(j)*O2(j)-mu_o*O2(j)));
P2(j+1) = P2(j)+(dt*(Ko*M12(j)*O2(j)-mu_p*P2(j)));
end
Let's plot M1 and M12 separately.
figure
plot(T, M1)
figure
plot(T, M12)
Are the values in M12 actually exactly 0?
[minvalue, maxvalue] = bounds(M12)
So that looks correct. How about the other variables whose names end with 2?
[minvalue, maxvalue] = bounds(M22)
[minvalue, maxvalue] = bounds(M32)
[minvalue, maxvalue] = bounds(M42)
[minvalue, maxvalue] = bounds(M52)
[minvalue, maxvalue] = bounds(M62)
[minvalue, maxvalue] = bounds(O2)
[minvalue, maxvalue] = bounds(P2)
Given the data, all those plots you showed look correct to me. Could you say more about what you believe MATLAB is doing / plotting incorrectly?
0 Comments
More Answers (0)
See Also
Categories
Find more on Function Creation 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!