Effacer les filtres
Effacer les filtres

Tangent line to a curve at a given point

35 vues (au cours des 30 derniers jours)
x y
x y le 6 Oct 2013
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 commentaire
Jan
Jan le 6 Oct 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.

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 6 Oct 2013
Modifié(e) : Azzi Abdelmalek le 6 Oct 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 commentaires
Christopher Creutzig
Christopher Creutzig le 8 Nov 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 le 7 Oct 2019
what is the use of the tang equation you used?
could you please explain it?

Connectez-vous pour commenter.

Plus de réponses (1)

Varun Kumar
Varun Kumar le 2 Nov 2019
2*(x^(1/2)) 1,2

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by