Plot two looping variables

1 view (last 30 days)
Tomas White
Tomas White on 2 May 2022
Commented: Voss on 3 May 2022
Hello! I have this code which generates multiple values of the variable "CL" by iterating the variable "aoa", my problem is that when I try to plot both variables I generate a graph per "aoa" iteration and not all iterations in a single graph. I tried various methods and code combinations but nothing seems to do the job. Any help is much aprreciated!
%LLT
fprintf('Lifting line theory - 7.1 \n')
%Inputs
fprintf('------------------------------------------------------------- \n')
zeroliftd=-1.2;
aoainitiald=4;
aoafinald=10;
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
fprintf('------------------------------------------------------------- \n')
fprintf('------------------------------------------------------------- \n')
fprintf('Math process corresponding to angle of attack (degrees) =')
dispaoa=aoa*(180/pi);
disp(dispaoa)
matrix1=[station,phi,cosphi,sinphi1,sinphi3,sinphi5,sinphi7,miu];
fprintf('Table 7.1: \n')
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';
fprintf('Second member matrix for equation system 7.31: \n')
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];
fprintf('First member matrix for equation system 7.31: \n')
disp(equationmatrix1);
fprintf('------------------------------------------------------------- \n')
%equation system solver
matrixA=linsolve(equationmatrix1,Ltotal);
%An matrix
fprintf('Equation system 7.31 solution: \n')
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:
fprintf('Corresponding CL for inputed angle of attack:\n')
CLin=(matrixA(1,1))*3.14159*AR;
fprintf('CL:');
disp(CLin);
fprintf('------------------------------------------------------------- \n')
%Theoretical value of induced drag coefficient for inputed angle of attack:
fprintf('Corresponding induced theorical CD for inputed angle of attack:\n')
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+pi/180;
end
plot(aoa,CLin);

Accepted Answer

Voss
Voss on 2 May 2022
In order to see how aoa and CLin change in each iteration of the while loop, you can either: (1) plot them each time through the loop, or (2) collect all their values in arrays and plot the arrays after the loop.
Method 1 would have this kind of structure:
aoa=aoainitial;
while aoa < aoafinal
% ...
% calculate CLin
% ...
plot(aoa,CLin,'o'); % 'o' is a data marker, which is necessary to see a line with only one point
hold on % use hold on to keep each plotted line (in this case each plotted point)
aoa=aoa+pi/180;
end
Method 2 would have this kind of structure:
aoa_array = [];
CLin_array = [];
aoa=aoainitial;
while aoa < aoafinal
% ...
% calculate CLin
% ...
aoa_array(end+1) = aoa; % add the new values to the end of the arrays
CLin_array(end+1) = CLin;
aoa=aoa+pi/180;
end
plot(aoa_array,CLin_array); % plot the arrays
  2 Comments
Voss
Voss on 3 May 2022
You're welcome!

Sign in to comment.

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!