the maximum difference bewteen lines from a loop and plot

2 Ansichten (letzte 30 Tage)
Hello everyone!
Please, could you help me with a code
In my code, I'm plotting power and drag versus velocity. So, I need to calculate at which speed the maximum difference between two lines occur and the maximum difference between powers and drags. So, for example in figure 1, I need to calculate the value of maximum difference between orange and blue lines, and at which speed it occurs
My code is:
clear all; close all
W_takeoff = 10000;
W_landing=6000;
S = 20;
AR = 5;
cd0 = 0.02;
k = 1/pi/AR;
RC=0.51;
clalpha = 2*pi;
amin=2;
astall=12;
rho=1;
ct=0.001;
figure(1);hold on; xlabel('V');ylabel('D')
figure(2);hold on; xlabel('V');ylabel('D')
figure(3);hold on; xlabel('V');ylabel('P')
figure(4);hold on; xlabel('V');ylabel('P')
figure(5);hold on; xlabel('\alpha');ylabel('c_l/c_d^2')
i=0;
for alpha = amin:0.25:astall
i=i+1;
cl(i) = clalpha * alpha * pi/180;
V_takeoff(i) = sqrt(2*W_takeoff/rho/S/cl(i));
V_landing(i) = sqrt(2*W_landing/rho/S/cl(i));
cd(i) = cd0 + k * cl(i) * cl(i);
D_takeoff(i) = 0.5 * rho * V_takeoff(i) * V_takeoff(i) * S * cd(i);
D_landing(i) = 0.5 * rho * V_landing(i) * V_landing(i) * S * cd(i);
p_takeoff(i) = D_takeoff(i)*V_takeoff(i);
p_landing(i) = D_landing(i)*V_landing(i);
P_takeoff(i)=20000+500*V_takeoff(i);
T_takeoff(i)=20000/V_takeoff(i)+500;
P_landing(i)=20000+500*V_landing(i);
T_landing(i)=20000/V_landing(i)+500;
cl_cd2(i)=cl(i)/(cd(i)*cd(i));
ang(i)=alpha;
end
figure(1); plot(V_takeoff,D_takeoff)
hold on
plot(V_takeoff,T_takeoff)
title(['Takeoff'])
figure(2); plot(V_landing,D_landing)
hold on
plot(V_landing,T_landing)
title(['Landing'])
figure(3); plot(V_takeoff,p_takeoff)
hold on
plot(V_takeoff,P_takeoff)
title(['Takeoff'])
figure(4); plot(V_landing,p_landing)
hold on
plot(V_landing,P_landing)
title(['Landing'])

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 28 Mär. 2023
hello
see updated code below
clear all; close all
W_takeoff = 10000;
W_landing=6000;
S = 20;
AR = 5;
cd0 = 0.02;
k = 1/pi/AR;
RC=0.51;
clalpha = 2*pi;
amin=2;
astall=12;
rho=1;
ct=0.001;
i=0;
for alpha = amin:0.25:astall
i=i+1;
cl(i) = clalpha * alpha * pi/180;
V_takeoff(i) = sqrt(2*W_takeoff/rho/S/cl(i));
V_landing(i) = sqrt(2*W_landing/rho/S/cl(i));
cd(i) = cd0 + k * cl(i) * cl(i);
D_takeoff(i) = 0.5 * rho * V_takeoff(i) * V_takeoff(i) * S * cd(i);
D_landing(i) = 0.5 * rho * V_landing(i) * V_landing(i) * S * cd(i);
p_takeoff(i) = D_takeoff(i)*V_takeoff(i);
p_landing(i) = D_landing(i)*V_landing(i);
P_takeoff(i)=20000+500*V_takeoff(i);
T_takeoff(i)=20000/V_takeoff(i)+500;
P_landing(i)=20000+500*V_landing(i);
T_landing(i)=20000/V_landing(i)+500;
cl_cd2(i)=cl(i)/(cd(i)*cd(i));
ang(i)=alpha;
end
figure(1);
[max_delta,idelta] = max(abs(D_takeoff-T_takeoff));
plot(V_takeoff,D_takeoff,V_takeoff,T_takeoff,...
V_takeoff(idelta),D_takeoff(idelta),'dk',V_takeoff(idelta),T_takeoff(idelta),'dk')
hold on
plot([V_takeoff(idelta) V_takeoff(idelta)],[D_takeoff(idelta) T_takeoff(idelta)],'k--');
title(['Takeoff'])
xlabel('V');ylabel('D')
figure(2); plot(V_landing,D_landing,V_landing,T_landing)
title(['Landing'])
xlabel('V');ylabel('D')
figure(3); plot(V_takeoff,p_takeoff,V_takeoff,P_takeoff)
title(['Takeoff'])
xlabel('V');ylabel('P')
figure(4); plot(V_landing,p_landing,V_landing,P_landing)
title(['Landing'])
xlabel('V');ylabel('P')

Weitere Antworten (1)

Antoni Garcia-Herreros
Antoni Garcia-Herreros am 28 Mär. 2023
maxdiff=max(abs(p_takeoff-P_takeoff)); % Value of the maximum difference
i=find(abs(p_takeoff-P_takeoff)==maxdiff); % Index at which the maximum difference occurs

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by