Azzera filtri
Azzera filtri

Error Messages keep popping up: "Undefined function or variable"

1 visualizzazione (ultimi 30 giorni)
This is my Bifurcation code below. When I tried running it, it kept giving me the error message "??? Undefined function or variable 'C2'." and
"Error in ==> Bifurcation4 at 15
H1=c5*c6*c8*c9*C2;"
But this is after I have defined the necessary variables. Please help.
% The Matlab Codes for the forward bifurcation diagram
Rev_value=0.018:0.01:4;
Root_array=zeros (length (Rev_value), 2);
qI=0.001923; qA=0.00000004013; etaA=0.1213; etaQ=0.003808; w=0.5925;
Lambda=0.1598643e-7; theta=0.022;
delta=0.125; mu=0.01119; pi=0.464360344; deltaQ=6.847e-4; beta=1.086e-1;
qE=1.8113e-4; rhoQ=0.0815; a=0.16255; k=0.15; v1=0.71; v2=0.29;alpha=0.57e-1; deltaI=0.00000000223; rhoA=0.1; rhoI=0.0666666;
c1=mu+v1; c3=mu+alpha+v2; c4=1-k; c5=qE+delta+mu; c6=rhoA+mu; c7=delta*(1-a); c8=rhoI+qI+deltaI+mu; c9=rhoA+deltaQ+mu;
b1=1-theta; c2=1-w;
B=delta*a*c8*c9+c7*k*qI*rhoQ+c8*k*qE*rhoQ;
G=qI*c7*c6+qE*c8*c6;
H1=c5*c6*c8*c9*C2;
Unrecognized function or variable 'C2'.
H2=c5*c6*c8*c9*(c3*+c1*c2)-(b1*c2+c2*theta)*(c6*c9*c7*pi*beta+pi*G*beta*etaQ+pi*B*beta*etaA);
H3=c5*c6*c8*c9*(c3*c1-v1*v2)*(1-b1*Rev_value)-(c3*theta+c2*v1*theta)*(c6*c9*c7*pi*beta+pi*G*beta*etaQ+pi*B*beta*etaA);
hold on
for i=1:1:length(Rev_value);
Rev=Rev_value(i);
% bifurcation parameter
%Coefficients of quadratic equation H1, H2, H3
p=[H1,H2,H3];
r =roots(p);
len=length(r);
for t=1:1:len
if (imag(r(t))~=0) || (real(r(t))<0);
Root_array(i,t)=0;
else
Root_array(i,t)=r(t);
end
end
end
f=1;
while (Root_array(f,1)==0 && Root_array(f,1)==0 && Root_array(f,2)==0),f=f+1;
end
Rev_value_Cr=f;
for j=Rev_value_Cr:1:length(Rev_value)
Root_array(j,:) =sort(Root_array(j,:));
end
f1=Rev_value_Cr;
while (Root_array(f1,1)~=0)
f1=f1+1;
end
Rev_value_Cr2=f1;
Zero_1st=Rev_value(1,1:Rev_value_Cr2-1);
y_zero=zeros(1,length(Zero_1st));
Unstable =Rev_value(1,Rev_value_Cr:length(Rev_value));
figure (1)
plot(Unstable, Root_array(Rev_value_Cr:length(Rev_value),2),'r','LineWidth',3)
figure (2)
plot(Unstable,Root_array(Rev_value_Cr:length(Rev_value),2),'b','LineWidth',3)
ylabel('Force of Infection,(\lambda)','FontSize',12)
xlabel('reproduction number, R_o','FontSize',12)
hold off
figure (3)
plot(Rev_value,Root_array(:,1),'r',Rev_value,Root_array(:,2),'r',Rev_value,Root_array(:,2),'b','LineWidth',4)
ylabel('Force of Infection, \lambda','FontSize',12)
xlabel('reproduction number, R_o','FontSize',12)

Risposte (2)

Fangjun Jiang
Fangjun Jiang il 8 Lug 2023
up case, low case
  2 Commenti
Steven Lord
Steven Lord il 8 Lug 2023
To put it a bit more clearly, the variables C2 and c2 are not the same variable. You've defined c2 but have not defined C2. Your code is referencing C2 not c2.
In general, can you dynamically create variables with numbered names like c1, c2, c3, etc.? Yes.
Should you do this? The general consensus is no. That Answers post explains why this is generally discouraged and offers several alternative approaches. In this case, consider using a vector c with multiple elements and using c(1), c(2), etc. instead of c1, c2, etc.

Accedi per commentare.


Image Analyst
Image Analyst il 8 Lug 2023
There is just so much wrong with this that every time I fixed one thing, something else would pop up. For starters, use c2 instead of C2. I fixed several things but there is a lot more to correct. Finally I gave up. Just keep running it fixing one thing at a time like I did and eventually you'll fix all the errors.
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
% The Matlab Codes for the forward bifurcation diagram
Rev_value=0.018:0.01:4;
Root_array=zeros (length (Rev_value), 2);
qI=0.001923; qA=0.00000004013; etaA=0.1213; etaQ=0.003808; w=0.5925;
Lambda=0.1598643e-7; theta=0.022;
delta=0.125; mu=0.01119; pi=0.464360344; deltaQ=6.847e-4; beta=1.086e-1;
qE=1.8113e-4; rhoQ=0.0815; a=0.16255; k=0.15; v1=0.71; v2=0.29;alpha=0.57e-1; deltaI=0.00000000223; rhoA=0.1; rhoI=0.0666666;
c1=mu+v1; c3=mu+alpha+v2; c4=1-k; c5=qE+delta+mu; c6=rhoA+mu; c7=delta*(1-a); c8=rhoI+qI+deltaI+mu; c9=rhoA+deltaQ+mu;
b1=1-theta; c2=1-w;
B=delta*a*c8*c9+c7*k*qI*rhoQ+c8*k*qE*rhoQ;
G=qI*c7*c6+qE*c8*c6;
H1=c5*c6*c8*c9*c2;
H2=c5*c6*c8*c9*(c3*+c1*c2)-(b1*c2+c2*theta)*(c6*c9*c7*pi*beta+pi*G*beta*etaQ+pi*B*beta*etaA);
H3=c5*c6*c8*c9*(c3*c1-v1*v2)*(1-b1*Rev_value)-(c3*theta+c2*v1*theta)*(c6*c9*c7*pi*beta+pi*G*beta*etaQ+pi*B*beta*etaA);
hold on
for i = 1 : length(Rev_value)
fprintf('i = %d of %d\n', i, length(Rev_value));
Rev=Rev_value(i);
% bifurcation parameter
%Coefficients of quadratic equation H1, H2, H3
p=[H1,H2,H3];
r =roots(p);
len=length(r);
for t=1:1:len
% fprintf(' t = %d of %d\n', t, len);
if (imag(r(t))~=0) || (real(r(t))<0);
Root_array(i,t)=0;
else
Root_array(i,t)=r(t);
end
end
end
f=1;
while (Root_array(f,1)==0) && (Root_array(f,2)==0)
fprintf('In while loop 1, f = %d\n', f);
f=f+1;
if f > size(Root_array, 1)
break;
end
end
Rev_value_Cr=f;
for j=Rev_value_Cr:1:length(Rev_value)
fprintf('In for loop, j = %d\n', j);
Root_array(j,:) =sort(Root_array(j,:));
end
f1=Rev_value_Cr;
while (Root_array(f1,1)~=0)
fprintf('In while loop 2, f1 = %d\n', f1);
f1=f1+1;
if f1 > size(Root_array, 1)
break;
end
end
Rev_value_Cr2=f1;
Zero_1st=Rev_value(1,1:Rev_value_Cr2-1);
y_zero=zeros(1,length(Zero_1st));
Unstable =Rev_value(1,Rev_value_Cr:length(Rev_value));
figure (1)
plot(Unstable, Root_array(Rev_value_Cr:length(Rev_value),2),'r','LineWidth',3)
figure (2)
plot(Unstable,Root_array(Rev_value_Cr:length(Rev_value),2),'b','LineWidth',3)
ylabel('Force of Infection,(\lambda)','FontSize',12)
xlabel('reproduction number, R_o','FontSize',12)
hold off
figure (3)
plot(Rev_value,Root_array(:,1),'r',Rev_value,Root_array(:,2),'r',Rev_value,Root_array(:,2),'b','LineWidth',4)
ylabel('Force of Infection, \lambda','FontSize',12)
xlabel('reproduction number, R_o','FontSize',12)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by