How to plot a tangent line between two lines
이전 댓글 표시
I'm attempting to plot a tangent line to the red curve, but the tangent line must begin at the pinch point on the yellow line, which has been highlighted in black.

% Required Data
G = 1.356; L = 1.356; CL = 4.187*10^3; TL2 = 43.3; TL1 = 29.4;
% Red line data
x = linspace(TL1-10,TL2,1000);
y = 20312*exp(0.0524*x);
% Calculation to optain the yellow line data
H1 = 0.0165; TG1 = 29.4;
Hy1 = (((1.005+(1.88*H1))*1000)*(TG1 - 0)) + ((2.501*10^6)*H1);
Hy2 = ((L*CL*(TL2 - TL1))/G) + Hy1;
P1 = [TL1 Hy1];
P2 = [TL2 Hy2];
% Values for the yellow line
x_values = [TL1 TL2];
y_values = [Hy1 Hy2];
I want it to be like this black line

댓글 수: 2
Matt J
2021년 10월 31일
How do you define when something is "tangent" to a discretely sampled curve?
Abdullah Alhebshi
2021년 10월 31일
편집: Abdullah Alhebshi
2021년 10월 31일
채택된 답변
추가 답변 (1개)
Here is how it can be done with a relatively simple polyfit() and polyval() fcns along with syms and diff():
% Required Data
G = 1.356; L = 1.356; CL = 4.187*10^3; TL2 = 43.3; TL1 = 29.4;
% Red line data
x = linspace(TL1-10,TL2,1000);
y = 20312*exp(0.0524*x);
% Calculation to optain the yellow line data
H1 = 0.0165; TG1 = 29.4;
Hy1 = (((1.005+(1.88*H1))*1000)*(TG1 - 0)) + ((2.501*10^6)*H1);
Hy2 = ((L*CL*(TL2 - TL1))/G) + Hy1;
P1 = [TL1 Hy1];
P2 = [TL2 Hy2];
% Values for the yellow line
x_values = [TL1 TL2];
y_values = [Hy1 Hy2];
TL2 = 43.3; TL1 = 29.4;
x = linspace(TL1-10,TL2,1000);
y = 20312*exp(0.0524*x);
plot(x, y, 'b-x', 'LineWidth', 0.5);
hold on
FM = polyfit(x,y, 2); % Polynomial fit
syms z
FM_sym = FM(1)*z^2+FM(2)*z+FM(3);
dY = diff(FM_sym,z);
dY_Model = double(coeffs(dY));
z = x-TL1;
m = polyval(fliplr(dY_Model), TL1); % Slope
HY1 =polyval(FM, TL1); % y1 value
yy = m*z+HY1*1; % Tangent Line
plot(x, yy, 'k-', 'linewidth', 2), shg
legend('Fcn', 'Tangent Line', 'location', 'best')
hold off
카테고리
도움말 센터 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

