필터 지우기
필터 지우기

Calculate the difference between minimum values of a parabola and straight line (from a plot)

조회 수: 1 (최근 30일)
Hello everyone, please could you help me with a code.
How I can calculate the values from a plot? I need the difference between straight line (P) and between the minimum value of a parabola (P) for each curve.
So, for example in this curve, the difference between the straight blue curve and the first parabola, then the next straight line and green parabola and so on.
My code is:
clear all; close all
W = 60000;
S = 28.2;
AR=7;
cd0 = 0.02;
k = 0.04;
RC=0.51;
clalpha = 2*pi;
Psl=741000;
hv=0:1:10;
cdminp=4*cd0;
clminp=sqrt(3*cd0/k);
Vmin=sqrt(2*W/(1.225*28.2*clminp));
D=0.5*1.225*Vmin^2*S*cdminp;
Pminreq=D*Vmin;
deltaPgiven=RC*W;
figure(1);hold on; xlabel('V');ylabel('P')
hv=0:1:10;
for k1 = 1:numel(hv)
h = hv(k1);
i=0;
for alpha = 1:0.25:15
i=i+1;
rho(i)=1.225*exp(-h/10.4);
cl(i) = clalpha * alpha * pi/180;
V(i) = sqrt(2*W/rho(i)/S/cl(i));
L(i) = 0.5 * rho(i) * V(i) * V(i) * S * cl(i);
cd(i) = cd0 + k * cl(i) * cl(i);
D(i) = 0.5 * rho(i) * V(i) * V(i) * S * cd(i);
clcd(i) = cl(i)/cd(i);
p(i) = D(i)*V(i);
Ph(i)=Psl*(rho(i)/1.225).^0.75;
end
figure(1); plot(V,p)
hold on
plot(V,Ph);
end

채택된 답변

Les Beckham
Les Beckham 2023년 2월 10일
편집: Les Beckham 2023년 2월 10일
Maybe this?
W = 60000;
S = 28.2;
AR=7;
cd0 = 0.02;
k = 0.04;
RC=0.51;
clalpha = 2*pi;
Psl=741000;
hv=0:1:10;
cdminp=4*cd0;
clminp=sqrt(3*cd0/k);
Vmin=sqrt(2*W/(1.225*28.2*clminp));
D=0.5*1.225*Vmin^2*S*cdminp;
Pminreq=D*Vmin;
deltaPgiven=RC*W;
figure(1);hold on; xlabel('V');ylabel('P')
hv=0:1:10;
for k1 = 1:numel(hv)
h = hv(k1);
i=0;
for alpha = 1:0.25:15
i=i+1;
rho(i)=1.225*exp(-h/10.4);
cl(i) = clalpha * alpha * pi/180;
V(i) = sqrt(2*W/rho(i)/S/cl(i));
L(i) = 0.5 * rho(i) * V(i) * V(i) * S * cl(i);
cd(i) = cd0 + k * cl(i) * cl(i);
D(i) = 0.5 * rho(i) * V(i) * V(i) * S * cd(i);
clcd(i) = cl(i)/cd(i);
p(i) = D(i)*V(i);
Ph(i)=Psl*(rho(i)/1.225).^0.75;
end
figure(1); plot(V,p)
hold on
plot(V,Ph);
[pmin, imin] = min(p); % find the min p
deltas(k1) = Ph(1) - pmin; % calculate the difference
tolerance = 5000; % or whatever you want
if (abs(deltas(k1) - 300000) < tolerance)
fprintf('delta = %8.1f at h = %4.1f, rho = %.5f, V = %.2f, Ph = %.1f, p = %.1f\n', ...
deltas(k1), h, rho(imin), V(imin), Ph(imin), p(imin))
end
end
delta = 302330.3 at h = 4.0, rho = 0.83387, V = 64.31, Ph = 555317.0, p = 252986.7
legend(compose('h = %.1f', hv), 'location', 'northwest')
grid on
  댓글 수: 8
Les Beckham
Les Beckham 2023년 2월 10일
It just represents how close to 300000 the delta has to be to make the code print the results. Adjust as desired.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Torsten
Torsten 2023년 2월 10일
편집: Torsten 2023년 2월 10일
syms h V W S rho cd0 k cl Psl
eqn = V == sqrt(2*W/rho/S/cl);
cl = solve(eqn,cl);
Warning: Solutions are only valid under certain conditions. To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
cd = cd0 + k * cl^2;
D = 0.5 * rho * V * V * S * cd;
p = D*V;
Vmin = solve(diff(p,V)==0,V);
pmin = subs(p,V,Vmin);
Ph = Psl*(rho/1.225)^0.75;
hnum = 0:0.01:10;
Wnum = 60000;
Snum = 28.2;
rhonum = 1.225*exp(-hnum/10.4);
cd0num = 0.02;
knum = 0.04;
Pslnum = 741000;
for i = 1:numel(hnum)
Phnum(i) = double(subs(Ph,[rho Psl],[rhonum(i),Pslnum]));
pm = double(subs(pmin,[W S rho cd0 k],[Wnum Snum rhonum(i) cd0num,knum]));
pminnum(i) = pm(end);
deltaP(i) = Phnum(i)-pminnum(i);
end
format long
deltaP.'
ans = 1001×1
1.0e+05 * 5.322767552311991 5.316422010284389 5.310079836471793 5.303741027866013 5.297405581460750 5.291073494251587 5.284744763235998 5.278419385413340 5.272097357784856 5.265778677353669
idx = deltaP > 2.8e5 & deltaP < 3.2e5; % select those deltaP with 2.8e5 <= deltaP < = 3.2e5
[hnum(idx).' deltaP(idx).'] % Show these values together with the corresponding h values
ans = 77×2
1.0e+05 * 0.000036700000000 3.196913122178178 0.000036800000000 3.191616062324753 0.000036900000000 3.186321382077705 0.000037000000000 3.181029079029593 0.000037100000000 3.175739150774377 0.000037200000000 3.170451594907418 0.000037300000000 3.165166409025479 0.000037400000000 3.159883590726722 0.000037500000000 3.154603137610705 0.000037600000000 3.149325047278384
  댓글 수: 2
Alina Abdikadyr
Alina Abdikadyr 2023년 2월 10일
Thank you very much! But If I will have more h values, so may I display the deltaP values that are almost equal to 3?
Torsten
Torsten 2023년 2월 10일
편집: Torsten 2023년 2월 10일
Add the lines
idx = deltaP > 2.8e5 & deltaP < 3.2e5; % select those deltaP with 2.8e5 <= deltaP < = 3.2e5
[hnum(idx) deltaP(idx)] % Show these values together with the corresponding h values
at the end of the code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Text Data Preparation에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by