필터 지우기
필터 지우기

Tangent line to a curve at a given point

조회 수: 35 (최근 30일)
x y
x y 2013년 10월 6일
답변: Varun Kumar 2019년 11월 2일
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
Christopher Creutzig 2013년 11월 8일
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