Azzera filtri
Azzera filtri

Tangent line to a curve at a given point

35 visualizzazioni (ultimi 30 giorni)
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 Commento
Jan
Jan il 6 Ott 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.

Accedi per commentare.

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 6 Ott 2013
Modificato: Azzi Abdelmalek il 6 Ott 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 Commenti
Christopher Creutzig
Christopher Creutzig il 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 il 7 Ott 2019
what is the use of the tang equation you used?
could you please explain it?

Accedi per commentare.

Più risposte (1)

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

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by