How can I repeat a complete "for loop" with new values and keep it running until a condition gets satisfied?
Show older comments
I know this is not a very big problem for Matlab experts, but I am kind of new so please help me with my code. Any kind of help is appreciated. I consider a=18 to begin with. Values of Cl and Cd depend on it. Then the "for loop" (beginning with j) runs in order to calculate "tor" and finally "power". Now if "power" exceeds 10, I wish to decrease the value of "a" by 1 (i.e.a=17) and then repeat the whole loop again with new Cl and Cd, in order to calculate power. If power then becomes less than 10, it should stop and move to next "V" value, otherwise it should keep decreasing value of "a" until power becomes less than 10. How can I do that?
I am quoting my code here:
format long; clc; clear all; close all;
a=18; t=[0 1 2 3 4 ]; M=[7 8 9 10 11];
for X=1:1:length(M) V=M(:,X)
Cl=(0.1024*a)+0.293; Cd=(0.0002*a)+0.006;
j=1; for r=0.1:0.85:3.5
sum_T=0;
lambda=(3.5*12.56)/V;
Vr=sqrt(((2*V/3)^2)+((r*12.56)^2));
phi_1=atan(3.5/(lambda*r));
phi_2=(2*phi_1/3);
chord=(1/3)*(16*3.14*r/Cl)*(sin(phi_1/3))^2;
Cx=Cl*sin(phi_2)-Cd*cos(phi_2);
Cy=Cl*cos(phi_2)+Cd*sin(phi_2);
product=0.5*3*1.225*(Vr^2)*0.85;
dU=product*chord*Cx;
dT=dU*r;
sum_T=sum_T+dT;
tor(j)=dT;
j=j+1;
end
power=(12.56*sum(tor))/1000;
if (power<10)
output1=power
else
a=a-1 % i.e. a=17 (value of a)
% REPEAT THE WHOLE LOOP OF j AND CALCULATE power
%IF EVEN THEN power>10, WE DECREMENT "a" i.e. a= 16 and so on
end
end
1 Comment
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!