How to compare elements in an array?

7 views (last 30 days)
Alec Carruthers
Alec Carruthers on 6 Apr 2018
Commented: Alec Carruthers on 10 Apr 2018
My for loop cycles through a series of initial CL values and then a lot of calculations are done and I get final values for CL "CL_IC2." I want to see if any of the original CL values are equal to their corresponding CL_IC2 values.
clc;
clear;
%Design Mission
PAX = 250;
Cargo = 8000;
Range = 7000; %N. Miles
DRatio = .9524988;
PRatio = .23590495;
M = .85;
Vapp = 145; %Knots
TOFL = 10500; %Feet
a = 576.4592054; % Speed of Sound at 35,000 ft, KNOTS
V_cr = M*a; %Knots
R_all = Range + 200 + V_cr*.75; % n.miles
% Fuel Fraction for JT8D Engine with "R_all"
WfWto_8D = .49;
C_JT8D = .78; % SFC JT8D
C_JT9D = .61; % SFC JT9D
WfWto_9D = WfWto_8D*(C_JT9D/C_JT8D);
XX = .7; % Percent Max Fuel at Landing
%%%%%%%Values Changed Manually %%%%%%%%%
Abreast = 8; % Tested 4 - 8
N_aisle = 1; % Tested 1 & 2
Sweep = 30; % Degrees, Tested: 25, 30, 35, 40
AR = 8; % Tested: 6-9
Airfoil = 1; % Supercritical = 1, Conventional = 2.
% Assuming a Cl value so need a for loop.
CL=[.45:.01:.58];
n = length(CL);
DelM = cell(1,[]);
syms x
syms y
for i= 1:n
if Airfoil == 1 % Supercritical
DelM{i} = vpasolve((CL(i)==((-2*10^9)*x^6)-((1*10^8)*x^5)-((2*10^6)*x^4)-((2632.1*x^3)+124.37*x^2)-(5.8637*x)+.5475),x,[-.01 .015]);
end
if Airfoil == 2 %Conventional
DelM{i} = vpasolve((CL(i)==(-5.1087*x^2)-(2.9657*x)+.5509),x,[-.02 .04]);
end
NewDelM=cell2sym(DelM,'f');
MDiv=(M+.004)-NewDelM;
if Airfoil == 1
if Sweep == 25
%tc(i) = solve((y == (135.46.*(MDiv(i)).^4)-(449.48.*(MDiv(i)).^3)+(561.45.*(MDiv(i)).^2)-(313.45.*MDiv(i))+66.196),y);
tc(i) = solve((y == (3.7229.*(MDiv(i)).^2)-(6.7143.*MDiv(i))+3.1025));
end
if Sweep == 30
%tc(i) = solve((y == (339.86.*(MDiv(i)).^4)-(1139.2.*(MDiv(i)).^3)+(1434.1.*(MDiv(i)).^2)-(804.35.*MDiv(i))+169.83),y);
tc(i) = solve((y == (3.9755.*(MDiv(i)).^2)-(7.3602.*MDiv(i))+3.4805));
end
if Sweep == 35
%tc(i) = solve((y == (1098.2.*(MDiv(i)).^4)-(3728.7.*(MDiv(i)).^3)+(4751.1.*(MDiv(i)).^2)-(2693.7.*MDiv(i))+573.67),y);
tc(i) = solve((y == (6.2186.*(MDiv(i)).^2)-(11.535.*MDiv(i))+5.43));
end
if Sweep == 40
%tc(i) = solve((y == (13.242.*(MDiv(i)).^2)-(24.825.*MDiv(i))+11.718),y);
tc(i) = solve((y == (13.242.*(MDiv(i)).^2)-(24.825.*MDiv(i))+11.718));
end
end
if Airfoil == 2
if Sweep == 25
tc(i) = solve((y == (-.5307.*MDiv(i))+.5181),y);
end
if Sweep == 30
tc(i) = solve((y == (-.5037.*MDiv(i))+.5051),y);
end
if Sweep == 35
tc(i) = solve((y == (-.4671.*MDiv(i))+.4854),y);
end
if Sweep == 40
tc(i) = solve((y == (-.4267.*MDiv(i))+.4632),y);
end
end
Par = (cosd(Sweep)^2).*((tc).^2)*AR;
% Need the low speed CL_max_to and CL_max_ld. Use Figure 3 with "Par."
CL_TO(i) = solve((y == (-30.959.*(Par(i).^2))+12.965.*(Par(i))+1.1735),y);
CL_LD(i) = solve((y == (-23.26.*(Par(i).^2))+11.166.*(Par(i))+2.1806),y);
% Landing Wing Loading
WS_LD(i) = ((Vapp/1.3)^2).*(CL_LD(i))*(DRatio/296);
%Takeoff Wing Loading
WS_TO(i) = (WS_LD(i)./(1-(XX*WfWto_9D)));
% Initial Cruise Wing Loading
WS_IC = .965.*WS_TO;
% Initial Cruise CL
CL_IC = (WS_IC./(1481*PRatio*((M)^2)));
CL_IC1 = double(CL_IC);
CL_IC2 = round(CL_IC1,3)
%if CL(i) == CL_IC2
% CL_f = CL
%else
% CL_f = 0
%end
end
%end
You don't really need to worry about the middle just right before the for loop starts and the last few lines. Thank you.

Answers (1)

Prajit T R
Prajit T R on 9 Apr 2018
Hi Alec
You can use the 'find' function to obtain the values which are common between two arrays. For example:
a=[1 2 3 4]
b=[5 2 3 7]
find(a==b)
The above code returns:
ans =
2 3
In your case, this would be find(CL==CL_IC2)
I hope this helps.
Cheers

Categories

Find more on General Physics 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!