find a tangent values from plot

2 views (last 30 days)
Alina Abdikadyr
Alina Abdikadyr on 29 Jan 2023
Answered: Star Strider on 29 Jan 2023
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');

Answers (1)

Star Strider
Star Strider on 29 Jan 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')
Table = 6×8 table
V_p_max V_p_min Vstall Pmax Pmin Pstall minP Vminp _______ ____________ ______ _____ ______________ ______ ______ ______ 56.013 {0×0 double} 15.752 25000 {0×0 double } 12261 9283.1 26.626 55.822 {0×0 double} 17.051 22198 {0×0 double } 13273 10049 28.822 55.235 {0×0 double} 18.458 19710 {0×0 double } 14367 10878 31.199 53.92 {0×0 double} 19.98 17501 {0×0 double } 15552 11775 33.772 51.119 {[ 23.8756]} 21.628 15539 {[1.5539e+04]} 16835 12746 36.558 39.638 {[ 39.6377]} 23.412 13798 {[1.3798e+04]} 18223 13797 39.573
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.
.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!