Tangent line to a curve at a given point

35 次查看(过去 30 天)
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 个评论
Jan
Jan 2013-10-6
"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.

请先登录,再进行评论。

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-10-6
编辑:Azzi Abdelmalek 2013-10-6
%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 个评论
Christopher Creutzig
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 2019-10-7
what is the use of the tang equation you used?
could you please explain it?

请先登录,再进行评论。

更多回答(1 个)

Varun Kumar
Varun Kumar 2019-11-2
2*(x^(1/2)) 1,2

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by