How to get tangent line from a point not on the curve

조회 수: 32 (최근 30일)
Jiminy
Jiminy 2023년 3월 23일
편집: John D'Errico 2023년 3월 25일
Hi,
I have a curve, y = 945.75*x.^0.1002, and I am trying to get a tangent line from this curve that passes though the point (-1, 0). I'm doing this since I am trying to make a figure for considere's construction. I am not having any luck finding this.
clear; clc; close all;
x = [0:0.5:100];
y = 945.75*x.^0.1002;
plot(x, y)
grid on;

채택된 답변

John D'Errico
John D'Errico 2023년 3월 25일
편집: John D'Errico 2023년 3월 25일
The curve is:
syms x y x0
F(x) = 945.75*x.^0.1002;
A line tangent to the curve at any spcific location x0 would be simple to write. The equation would be:
y - y(x0) = y'(x0) * (x - x0)
that is, the old point-slope formulation of a line.
dF(x) = diff(F);
% This gives us the equation of the line as
TangentLine = y - F(x0) == dF(x0)*(x - x0)
TangentLine = 
This line must pass through the point (-1,0)
xsol = solve(subs(TangentLine,[x,y],[-1,0]),x0)
xsol = 
The tangent line is therefore given by the linear equation:
TangentLine = simplify(subs(TangentLine,x0,xsol))
TangentLine = 
Or, if you want it in terms of numbers, in a standard form, it would be
TangentLineNum = vpa(isolate(TangentLine,y))
TangentLineNum = 
subs(TangentLineNum,-1)
ans = 
So indeed it passes through that point. We can draw the line, and the curve.
y0 = double(F(xsol));
xsol = double(xsol);
fplot(F,[-1,xsol+1])
hold on
plot(double(xsol),double(y0),'gs')
plot([-1,xsol],[0,y0],'r-')
Oh. Wait! I just noticed the obvious answer, making it very easy.
What is the eqution of the line that passes through the point (x,y)=(-1,0)? Assume you don't know the slope of the line?
Again, the point-slope form of the equation applies here.
syms S x y
Line = (y - 0) == S*(x - (-1))
Line = 
We can draw infinitely many lines passing through that point. It would like like a star, emanating from the (-1,0) point. But only one line has the slope necessary to touch the curve at one point, the tangent line. The slope of that line is given again, by the slope of the curve, at point x0. As well, the curve at that point has a value of F(x0). We can now simply solve for the point on the curve x0, as
TangentLine = subs(Line,[x,y,S],[x0,F(x0),dF(x0)])
TangentLine = 
Again, x0 is the only unknown in that equation.
x0 = solve(TangentLine,x0)
x0 = 
And once we have the point x0, the slope of that line is given by dF(x0).
simplify(subs(Line,S,dF(x0)))
ans = 
vpa(ans)
ans = 
Again, we get the same identical line as before, but this is perhaps an easier way to visualize the solution.
  댓글 수: 2
Jiminy
Jiminy 2023년 3월 25일
Wow thanks! would never have thought of doing it the second way and was struggling with this.
John D'Errico
John D'Errico 2023년 3월 25일
Yes. The first way I did it was a little messier. I think the problem is, you (not just you, me too) tend to focus on the concept of a tangent line. And that does that mean? We mentally decide to construct a line tangent to the curve. And then only at the end we add in the information that the line must pass through a specified point. In reality of course, what matters is the line can be defined from either perspective, but things are so much cleaner from the second perspective.
It is really a teaching moment in my eyes, that we all need to use all of the information we have available, to not focus too tightly on some aspect of the problem. It was something I glossed over at first too, only finding the second solution as an afterthought. As I said, this is worth remembering for all of us.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 3월 24일
Note that the point at which you're trrying to compute real valued tangent does not exist of the given y(x) fcn. Therefore, if to consider instead of (-1, 0) the point at (2, 1015), then it shows the computed tangent line at (2, 1015). Here is the complete solution code in three versions. Version 3 has a better view of the given fcn vs. tanget line:
clearvars; close all
% Version 1
syms y(x)
y(x) = 945.75*x.^0.1002;
dy = (diff(y(x),x));
x0=2; y0=1015; % Tangent line is found @ (2, 1015) point
m = double(subs(dy,x0));
b =y0-m*x0;
y = @(x)945.75*x.^0.1002;
figure
fplot(y, [0, 100], 'r--', 'linewidth', 1.5)
grid on
hold on
T = @(x)m*x+b;
fplot(T, [0,100], 'k', 'linewidth', 2)
plot(x0, y0, 'bs', 'markerfacecolor', 'y', 'markersize', 9)
legend('y(x)', 'tangent at (2, 1015)', 'point (2, 1015)','Location', 'SE')
grid on
xlabel('x')
ylabel('y(x), tangent T(x)')
hold off
% Version 2
clearvars
syms y(x)
y(x) = 945.75*x.^0.1002;
dy = (diff(y(x),x));
x0=2; y0=1015; % At (2, 1015) point
m = double(subs(dy,x0));
b =y0-m*x0;
y = @(x)945.75*x.^0.1002;
x = linspace(0,100, 1000);
figure
plot(x, y(x), 'r--', 'linewidth', 1.5)
grid on
hold on
T = @(x)m*x+b;
plot(x, T(x), 'k', 'linewidth', 2)
plot(x0, y0, 'bs', 'markerfacecolor', 'y', 'markersize', 9)
legend('y(x)', 'tangent at (2, 1015)', 'point (2, 1015)','Location', 'SE')
grid on;
xlabel('x')
ylabel('y(x), tangent T(x)')
hold off
% Version 1
syms y(x)
y(x) = 945.75*x.^0.1002;
dy = (diff(y(x),x));
x0=2; y0=1015; % Tangent line is found @ (2, 1015) point
m = double(subs(dy,x0));
b =y0-m*x0;
y = @(x)945.75*x.^0.1002;
figure
fplot(y, [0, 10], 'r--', 'linewidth', 1.5)
grid on
hold on
T = @(x)m*x+b;
fplot(T, [0,10], 'k', 'linewidth', 2)
plot(x0, y0, 'bs', 'markerfacecolor', 'y', 'markersize', 9)
legend('y(x)', 'tangent at (2, 1015)', 'point (2, 1015)','Location', 'SE')
grid on
xlabel('x')
ylabel('y(x), tangent T(x)')
hold off
  댓글 수: 4
Jiminy
Jiminy 2023년 3월 24일
Is there no way to get a tangent of the curve that passes through (-1, 0)? I'll put a picture in for what I mean. I am trying to find a way to accurately get a tangent through (-1, 0) of any power curve that is inputted
clear; clc; close all;
x = [0:0.001:0.2];
y = 945.75*x.^0.1002;
s = [-1:0.001:0.2];
z = 678.738738739 * s + 678.738738739;
plot(x, y)
xlim ([-1 0.2]);
ylim ([0 950])
grid on;
hold on;
plot(s, z)
John D'Errico
John D'Errico 2023년 3월 25일
@Jiminy - read my answer

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by