Calculate the difference between minimum values of a parabola and straight line (from a plot)
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
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
2 comentarios
Alina Abdikadyr
el 10 de Feb. de 2023
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.
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
