Finding Slope of a curve at a specific point

68 views (last 30 days)
How can i calculate the slope of the curve at the point presented in a red star.

Accepted Answer

Star Strider
Star Strider on 18 Aug 2022
Try something like this —
x = linspace(1, 10);
y = sin(2*pi*x/3) + cos(2*pi*x/9);
dydx = gradient(y) ./ gradient(x);
xv = rand*max(x) % Choose A Random Point
xv = 4.1240
yv = interp1(x, y, xv) % Interpolate 'y' Vector
yv = -0.2597
dydxv = interp1(x, dydx, xv) % Interpolate Derivative Vector
dydxv = -1.6437
figure
plot(x, y)
hold on
plot(xv, yv, '*r')
hold off
text(xv, yv, sprintf(' \\leftarrow Slope at (%.3f, %.3f) = %.3f',xv, yv, dydxv), 'Horiz','left', 'Vert','middle')
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!