Loop a whole code to display each variation of a variable

2 views (last 30 days)
Greetings! I have been making this code for my matlab introduction class in which I want to obtain a different value of the variables "CL" and "CD". I made a while loop but I can't figure out why my code isn't "looping" and is just giving me the result for "CL" and "CD" with my first loop value (equal to 4, appears as "aoainitiald" on my code). Any help is much appreciated.
%LLT
fprintf('Lifting line theory - 7.1 \n')
%Inputs
fprintf('------------------------------------------------------------- \n')
fprintf('Inputs: \n')
fprintf('------------------------------------------------------------- \n')
zeroliftd=-1.2;
aoainitiald=4; %initial value
aoafinald=10; %final value
AR=9;
fprintf('------------------------------------------------------------- \n')
%input adjustments (deg to rad)
aoainitial=((aoainitiald*pi)/180);
aoafinal=((aoafinald*pi)/180);
zerolift=((zeroliftd*pi)/180);
%Station phi values
station=[1,2,3,4]';
s1phi=22.5;
s2phi=45;
s3phi=67.5;
s4phi=90;
phin=[s1phi,s2phi,s3phi,s4phi];
phi=phin.';
%Calculus - table 7.1
cosphi=cosd(phi);
sinphi1=sind(phi);
sinphi3=sind(3*phi);
sinphi5=sind(5*phi);
sinphi7=sind(7*phi);
miu=0.24933*(1-0.6*cosd(phi));
aoa=aoainitial;
while ((aoa) <= (aoafinal))
%table 7.1 display
matrix1=[station,phi,cosphi,sinphi1,sinphi3,sinphi5,sinphi7,miu];
disp(matrix1);
fprintf('------------------------------------------------------------- \n')
%equation 7.31
%equation second member
L1=((matrix1(1,8))*(aoa-zerolift)*(matrix1(1,4)));
L2=((matrix1(2,8))*(aoa-zerolift)*(matrix1(2,4)));
L3=((matrix1(3,8))*(aoa-zerolift)*(matrix1(3,4)));
L4=((matrix1(4,8))*(aoa-zerolift)*(matrix1(4,4)));
Ltotaln=[L1,L2,L3,L4];
Ltotal=Ltotaln';
disp(Ltotal);
fprintf('------------------------------------------------------------- \n')
%matrix: A1
ma11=(matrix1(1,4))*((matrix1(1,8))+(matrix1(1,4)));
ma13=(matrix1(2,4))*((matrix1(2,8))+(matrix1(2,4)));
ma15=(matrix1(3,4))*((matrix1(3,8))+(matrix1(3,4)));
ma17=(matrix1(4,4))*((matrix1(4,8))+(matrix1(4,4)));
ma1n=[ma11,ma13,ma15,ma17];
ma1=ma1n';
%matrix: A3
ma31=(matrix1(1,5))*(3*(matrix1(1,8))+(matrix1(1,4)));
ma33=(matrix1(2,5))*(3*(matrix1(2,8))+(matrix1(2,4)));
ma35=(matrix1(3,5))*(3*(matrix1(3,8))+(matrix1(3,4)));
ma37=(matrix1(4,5))*(3*(matrix1(4,8))+(matrix1(4,4)));
ma3n=[ma31,ma33,ma35,ma37];
ma3=ma3n';
%matrix: A5
ma51=(matrix1(1,6))*(5*(matrix1(1,8))+(matrix1(1,4)));
ma53=(matrix1(2,6))*(5*(matrix1(2,8))+(matrix1(2,4)));
ma55=(matrix1(3,6))*(5*(matrix1(3,8))+(matrix1(3,4)));
ma57=(matrix1(4,6))*(5*(matrix1(4,8))+(matrix1(4,4)));
ma5n=[ma51,ma53,ma55,ma57];
ma5=ma5n';
%matrix: A7
ma71=(matrix1(1,7))*(7*(matrix1(1,8))+(matrix1(1,4)));
ma73=(matrix1(2,7))*(7*(matrix1(2,8))+(matrix1(2,4)));
ma75=(matrix1(3,7))*(7*(matrix1(3,8))+(matrix1(3,4)));
ma77=(matrix1(4,7))*(7*(matrix1(4,8))+(matrix1(4,4)));
ma7n=[ma71,ma73,ma75,ma77];
ma7=ma7n';
%matrix system
%equation first member
equationmatrix1=[ma1,ma3,ma5,ma7];
disp(equationmatrix1);
fprintf('------------------------------------------------------------- \n')
%equation system solver
matrixA=linsolve(equationmatrix1,Ltotal);
%An matrix
fprintf('A1 = ')
disp(matrixA(1,1));
fprintf('A3 = ')
disp(matrixA(2,1));
fprintf('A5 = ')
disp(matrixA(3,1));
fprintf('A7 = ')
disp(matrixA(4,1));
fprintf('------------------------------------------------------------- \n')
%Lift coefficient for inputed angle of attack:
CLin=(matrixA(1,1))*3.14159*AR;
fprintf('CL:');
disp(CLin);
fprintf('------------------------------------------------------------- \n')
%Theoretical value of induced drag coefficient for inputed angle of attack:
CDin=(((CLin)^2)/(3.14159*AR))*(1+((3*(matrixA(2,1))^2)/((matrixA(1,1))^2))+((5*(matrixA(3,1))^2)/((matrixA(1,1))^2))+((7*(matrixA(4,1))^2)/((matrixA(1,1))^2)));
fprintf('Cd:');
disp(CDin);
aoa=aoa+1;
end

Accepted Answer

Voss
Voss on 2 May 2022
Edited: Voss on 2 May 2022
Since aoa is in radians, rather than incrementing it by 1 radian each time, perhaps you mean to increment it by pi/180 radians, which is equivalent to 1 degree, each time.
That is, change this:
aoa=aoa+1;
to:
aoa=aoa+pi/180;
and you will see results over multiple iterations.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!