Borrar filtros
Borrar filtros

Tangent line to a curve at a given point

35 visualizaciones (últimos 30 días)
x y
x y el 6 de Oct. de 2013
Respondida: Varun Kumar el 2 de Nov. de 2019
Hy, I want to plot tangent line for function given by one point.
I tried to solve this problem but didnt work well Someone can me help me,pls
syms x
func = -2*x^2+4;
x0 = 1;
% f(x)'= -4*x
m=diff(func)
% m == f(x0)'= -4*x0
fdx = inline(m, 'x');
fdx(x0)
% x == (x - x0)
xX =(x - x0)
% c == f(x0)
fx = inline('-2*x^2+4', 'x');
c = fx(x0)
ezplot(x)
hold on
% y = m*x + c
y=m*xX+c;
ezplot(y)
  1 comentario
Jan
Jan el 6 de Oct. de 2013
"Didn't work well" is a DON'T in a forum. Do not let us guess the problems, but explain them to save the time of the readers. The less the readers have to guess, the more likely is a matching answer.

Iniciar sesión para comentar.

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 6 de Oct. de 2013
Editada: Azzi Abdelmalek el 6 de Oct. de 2013
%Example
t=0:0.01:10
y=sin(t)
plot(t,y)
%-------------------------
dy=diff(y)./diff(t)
k=220; % point number 220
tang=(t-t(k))*dy(k)+y(k)
hold on
plot(t,tang)
scatter(t(k),y(k))
hold off
  3 comentarios
Christopher Creutzig
Christopher Creutzig el 8 de Nov. de 2013
I don't see symbolic in Azzi's answer, but as to your question: if y is symbolic, then diff(y) (or diff(y,t)) is exact and there is no room for some “more precise” way of getting a symbolic derivative. (Which is not to say that for some applications, getting higher order approximations like taylor(y,t) might not be better. But again, those are exact.)
Numerically, integration is easy and differentiating is hard. (Hard as in: Hard to get any kind of reliable answers for a wide range of functions.) Symbolically, it's the other way round: Differentiating is dead easy, integrating is still more of an art than a science.
noora alahmed
noora alahmed el 7 de Oct. de 2019
what is the use of the tang equation you used?
could you please explain it?

Iniciar sesión para comentar.

Más respuestas (1)

Varun Kumar
Varun Kumar el 2 de Nov. de 2019
2*(x^(1/2)) 1,2

Categorías

Más información sobre Symbolic Math Toolbox 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!

Translated by