Max command MATLAB

108 Views Asked by At

My friends and I have been trying to resolve a localized problem in MATLAB code -

It deals with the "max" command - we are trying to find the maximum of R01 and R02, and plot this max against varying values of gamma1. The problem is in the for loop.\

The error message is:

In an assignment  A(I) = B, the number of elements in B and I must be the same.
Error in SolverDEqnsBoth (line 68)
R0(i) = max(transpose(R01),R02);

Here is the code:

B       = 2000;
mu      = 0.02;
deltaT  = 0.24;
deltaA  = 1.00;
alpha1  = 0.10;
alpha2  = 0.50;
beta1   = 2.00;
beta2   = 0.47;
gamma1  = 2.00;
gamma2  = 1.50;
v1      = 0.009;
v2      = 0.19;
c1      = 100;
c3      = 2.00;
c4      = 0.50;
N       = 35000;

%%%== Initial conditions ==
S0 = 10000;
H0 = 3000;
E10 = 3500;
E20 = 2000;
I10 = 4000;
I20 = 2500;
T10 = 3000;
T20 = 2000;
A10 = 1800;
A20 = 1700;
A30 = 800;
A40 = 700;

y0 = [S0 H0 E10 E20 I10 I20 T10 T20 A10 A20 A30 A40];

tf = 100;

[t y] = ode15s(@DEqnsBoth,[0:0.1:100],y0);

S = y(:,1);
H = y(:,2);
E1 = y(:,3);
E2 = y(:,4);
I1 = y(:,5);
I2 = y(:,6);
T1 = y(:,7);
T2 = y(:,8);
A1 = y(:,9);
A2 = y(:,10);
A3 = y(:,11);
A4 = y(:,12);


N = S + H + E1 + E2 + I1 + I2 + T1 + T2 + A1 + A2 + A3 + A4;

R01 =(beta1*c1*v1*B)/ ((mu + deltaT + gamma2)*(mu + v1 + gamma1))*mu*N;
R02 = (beta2*c3*B)/((mu+alpha1)*mu*N);

for i = 1:length(gamma1)
gamma1 = [0:0.005:5];
R0 = zeros(1, length(gamma1));
R0(i) = max(transpose(R01),R02);
end 
plot(gamma1,R0)

%plot(t,100.*( S)./N, 'r')
%hold on
%axis square
 %xlabel('days')
 %ylabel('Prevalence (% infected)')
 %axis([0 100 0 100])

Thanks in advance for any help.

1

There are 1 best solutions below

5
On BEST ANSWER

try putting in:

 R0(i) = max([transpose(R01),R02]);

I'm getting an error, but it shouldn't be important though.

Undefined function 'DEqnsBoth' for input arguments of type 'double'.

Can you please write down what you get when you do the folowing:

size(R01)
size(R02)