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

10 Ansichten (letzte 30 Tage)
Jiminy am 23 Mär. 2023
Bearbeitet: John D'Errico am 25 Mär. 2023
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;
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

John D'Errico am 25 Mär. 2023
Bearbeitet: John D'Errico am 25 Mär. 2023
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 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
John D'Errico am 25 Mär. 2023
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.

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Sulaymon Eshkabilov am 24 Mär. 2023
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 Kommentare3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden
John D'Errico am 25 Mär. 2023

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Function Creation in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by