필터 지우기
필터 지우기

Plot the line Tangent at a given point

조회 수: 8 (최근 30일)
ILoveMath
ILoveMath 2022년 4월 6일
댓글: Star Strider 2022년 4월 6일
I'm new to Matlab and am trying to plot the following:
Graph the function y = 3x^2 for x = 0 to x = 5 in steps of 0.1 as a solid blue line.
On the same plot, graph the equation of the line tangent to y = 3x^2 at x = 2 as a dashed red line.
I got the first part done. Just can't figure out how to plot the line tangent.
  댓글 수: 1
Voss
Voss 2022년 4월 6일
What did you figure out so far about the tangent line? Do you know its slope? Did you figure out an equation for it?

댓글을 달려면 로그인하십시오.

채택된 답변

Sam Chak
Sam Chak 2022년 4월 6일
As a self-proclaimed math lover, I presume that you already know mathematically how to find the tangent line by hand.
If you are asking how to find the slope the MATLAB way, here is one of several approaches:
h = 0.001; % step size
x = 0:h:5;
y = 3*x.^2; % the function, f(x)
plot(x, y, 'linewidth', 1.5)
hold on % retain current figure
p = 2; % x = 2
plot(p, 3*p^2, 'o', 'linewidth', 1.5) % display the point at y(2)
w = gradient(y)/h; % compute the slope of the function
m = w(p/h + 1); % slope at x = 2
c = y(p/h + 1) - m*x(p/h + 1); % y-intercept
z = m*x + c; % line equation at x = 2
plot(x, z, 'linewidth', 1.5)
hold off
grid on
xlabel('x')
ylabel('y')
title('y = f(x) and the tangent line at x = 2')
legend('function f(x)', 'the point at y(2)', 'tangent line at x = 2', 'location', 'northwest')
  댓글 수: 1
Star Strider
Star Strider 2022년 4월 6일
It is not considered appropriate to provide a complete solution to homework problems.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by