find a tangent values from plot
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos

Hello everyone! Please could you help me how to find values from the tangent lines that goes from (0;0) to each parabolas.
My code is :
clear all; close all
W = 10000;
S = 40;
AR = 7;
cd0 = 0.005;
k = 1 / pi / AR;
clalpha = 2*pi;
Psl=25000;
figure(1);hold on; xlabel('V');ylabel('P');
hv=0:1.6484:8.242;
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));
cd(i) = cd0 + k * cl(i) * cl(i);
D(i) = 0.5 * rho(i) * V(i) * V(i) * S * cd(i);
P(i) = D(i)*V(i);
Ph(i)=Psl*(rho(i)/1.225).^0.75;
end
Vm(k1,:) = V;
Pm(k1,:) = P;
Pmh(k1,:) = Ph;
xix = find(diff(sign(D.*V-Ph)));
if ~isempty(xix)
for k3 = 1:numel(xix)
idxrng = max(xix(k3)-1,1) : min(numel(V),xix(k3)+1);
xv(k3) = interp1(P(idxrng)-Ph(idxrng), V(idxrng), 0);
yv(k3) = interp1(V(idxrng),P(idxrng), xv(k3));
Xm{k1,k3} = xv(k3); % Intersection X-Matrix
Ym{k1,k3} = yv(k3); % Intersection Y-Matrix
end
end
figure(1)
plot(V,P)
hold on
plot(V,Ph)
xlim([0 90])
ylim([0 45000])
plot(xv, yv, 's', 'DisplayName',sprintf('Intersections %d',k1)) % Plot Intersections (Optional)
[minV,Vnidx] = min(V);
Vstall(k1,:) = minV;
Pstall(k1,:) = P(Vnidx);
[Pmin,idx] = min(P);
minP(k1,:) = Pmin;
Vm(k1,:) = V(idx);
Vminp=Vm(:,1);
end
Table = cell2table(cat(2,Xm,Ym), 'VariableNames',{'V_p_max','V_p_min','Pmax','Pmin'});
Table = addvars(Table, Vstall, 'After','V_p_min');
Table = addvars(Table, Pstall, minP,Vminp, 'After','Pmin');
Vpmin=[Vstall(1:4);cell2mat(Xm(5,2));cell2mat(Xm(6,2))];
Vpmax=cell2mat(Xm(:,1));
Vfinal=[Vpmax,Vpmin];
figure(1);legend('H=Sl','','','H=1.6484','','','H=3.2968','','','H=4.9452','','','H=6.5936', '','','H=8.242');
0 comentarios
Respuestas (1)
Star Strider
el 29 de En. de 2023
I am not certain what tangent (slope) you want. I am assuming it is from (0,0) to where the tangent line touches each parabols.
If you want a line from (0,0) to a point on each parabola, as luck would have it, that is the minimum value for the slope, since:
and by definition (here)
, and since:
the lowest value of the slope will be the value that satisfies that relation. That gives:
[m_min,ix] = min(P./V);
for each parabola, and the corresponding line will be:
plot([0 V(ix)], [0 P(ix)])
That is plotted in the last plot call, producing lines that extend from the (0,0) origin to those points on the parabolas. The points differ, however the slopes are essentially all the same for each parabola.
If you want different tangents, please describe them in a bit more detail.
Try this —
W = 10000;
S = 40;
AR = 7;
cd0 = 0.005;
k = 1 / pi / AR;
clalpha = 2*pi;
Psl=25000;
figure(1);hold on; xlabel('V');ylabel('P');
hv=0:1.6484:8.242;
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));
cd(i) = cd0 + k * cl(i) * cl(i);
D(i) = 0.5 * rho(i) * V(i) * V(i) * S * cd(i);
P(i) = D(i)*V(i);
Ph(i)=Psl*(rho(i)/1.225).^0.75;
end
Vm(k1,:) = V;
Pm(k1,:) = P;
Pmh(k1,:) = Ph;
xix = find(diff(sign(D.*V-Ph)));
if ~isempty(xix)
for k3 = 1:numel(xix)
idxrng = max(xix(k3)-1,1) : min(numel(V),xix(k3)+1);
xv(k3) = interp1(P(idxrng)-Ph(idxrng), V(idxrng), 0);
yv(k3) = interp1(V(idxrng),P(idxrng), xv(k3));
Xm{k1,k3} = xv(k3); % Intersection X-Matrix
Ym{k1,k3} = yv(k3); % Intersection Y-Matrix
end
end
figure(1)
hp{k1} = plot(V,P);
c{k1} = hp{k1}.Color;
hold on
plot(V,Ph)
xlim([0 90])
ylim([0 45000])
plot(xv, yv, 's', 'DisplayName',sprintf('Intersections %d',k1)) % Plot Intersections (Optional)
[minV,Vnidx] = min(V);
Vstall(k1,:) = minV;
Pstall(k1,:) = P(Vnidx);
[Pmin,idx] = min(P);
minP(k1,:) = Pmin;
Vm(k1,:) = V(idx);
Vminp=Vm(:,1);
% dPdV(k1,:) = gradient(P) ./ gradient(V);
[m_min,ix] = min(P./V);
% Cm = [P(ix) V(ix)]
plot([0 V(ix)], [0 P(ix)], '-', 'LineWidth',1, 'Color',c{k1})
plot(V(ix), P(ix), 'd', 'Color',c{k1})
% Q1 = size(dPdV{k1})
end
Table = cell2table(cat(2,Xm,Ym), 'VariableNames',{'V_p_max','V_p_min','Pmax','Pmin'});
Table = addvars(Table, Vstall, 'After','V_p_min');
Table = addvars(Table, Pstall, minP,Vminp, 'After','Pmin')
Vpmin=[Vstall(1:4);cell2mat(Xm(5,2));cell2mat(Xm(6,2))];
Vpmax=cell2mat(Xm(:,1));
Vfinal=[Vpmax,Vpmin];
lgdstr = [{'H=SI'} compose('H=%.4f',hv(2:end))];
figure(1);
% legend('H=Sl','','','H=1.6484','','','H=3.2968','','','H=4.9452','','','H=6.5936', '','','H=8.242');
legend([hp{:}],lgdstr, 'Location','best')
The tangent lines go from (0,0) to the appropriate points on each parabola. The tangent points on each parabola are plotted with diamond markers in the colors of the parabola.
.
0 comentarios
Ver también
Categorías
Más información sobre Mathematics and Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
