MATLAB: Equations using corresponding rows of data to give ‘n’ outputs

for loopMATLABnonlinearrandom

I have been writing a code to solve a flight mechanics problem involving finding solutions to non linear equations. The original code that I wrote didn't have the random input variables as seen below, e.g instead of E = a random number between 0.75 and 0.85, E = 0.8.
I changed the input variables to be random and to give me 'n' outputs as seen below.
I can't work out how to change the code starting from the bold part below to now account for there being 'n' outputs and for the corresponding rows of data to be used in the equations. I'm getting confused where to use '.' in the For loop.
The outcome that I want is to get 'n' values for ROC_max and Gama_max, corresponding to the rows of input variables.
n=10;
Rho=1.225;
E_min=0.75;
E_max=0.85;
E=E_min+(E_max-E_min)*rand(n,1)
B_min=15;
B_max=25;
B=B_min+(B_max-B_min)*rand(n,1)
S_min=35;
S_max=55;
S=S_min+(S_max-S_min)*rand(n,1)
W_min=70000;
W_max=140000;
W=W_min+(W_max-W_min)*rand(n,1)
CD0_min=0.012;
CD0_max=0.02;
CD0=CD0_min+(CD0_max-CD0_min)*rand(n,1)
T_min=40000;
T_max=60000;
T=T_min+(T_max-T_min)*rand(n,1)
AR=B.^2./S
CL=0.05:0.01:8;
for i=1:length(CL)
Gama_0=0;
Error=1;
while Error>1e-6
V(i)=sqrt((2*cosd(Gama_0)*W)/(Rho*S*CL(i)));
CD=CD0+((CL(i)^2)/(pi*E*AR));
Gama_new(i)=asind((T-0.5*Rho*(V(i)^2)*S*CD)/W);
Error=abs(Gama_0-Gama_new(i));
Gama_0=Gama_new(i);
end
end
V_horiz=V.*cosd(Gama_new);
ROC=sind(Gama_new).*V;
Gama=atand(ROC./V_horiz);
ROC_max=mac(ROC)
Gama_max=max(Gama)

Best Answer

n=10;
Rho=1.225;
E_min=0.75;
E_max=0.85;
E=E_min+(E_max-E_min)*rand(n,1)
B_min=15;
B_max=25;
B=B_min+(B_max-B_min)*rand(n,1)
S_min=35;
S_max=55;
S=S_min+(S_max-S_min)*rand(n,1)
W_min=70000;
W_max=140000;
W=W_min+(W_max-W_min)*rand(n,1)
CD0_min=0.012;
CD0_max=0.02;
CD0=CD0_min+(CD0_max-CD0_min)*rand(n,1)
T_min=40000;
T_max=60000;
T=T_min+(T_max-T_min)*rand(n,1)
AR=B.^2./S
CL=0.05:0.01:8;
for i=1:length(CL)
Gama_0=0;
Error=1;
while any(Error>1e-6)
V(i, :)=sqrt((2.*cosd(Gama_0(:)).*W)./(Rho.*S.*CL(i)));
CD=CD0+((CL(i)^2)./(pi.*E.*AR));
Gama_new(i,:)=asind((T-0.5.*Rho.*(V(i).^2).*S.*CD)./W);
Error=abs(Gama_0-Gama_new(i,:));
Gama_0=Gama_new(i,:);
end
end
V_horiz=V.*cosd(Gama_new);
ROC=sind(Gama_new).*V;
Gama=atand(ROC./V_horiz);
ROC_max=max(ROC)
Gama_max=max(Gama)