Calculate the difference between minimum values of a parabola and straight line (from a plot)
조회 수: 4 (최근 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
댓글 수: 0
채택된 답변
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
legend(compose('h = %.1f', hv), 'location', 'northwest')
grid on
댓글 수: 8
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
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);
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.'
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!