Finding Slope of a curve at a specific point
68 views (last 30 days)
Show older comments
How can i calculate the slope of the curve at the point presented in a red star.
0 Comments
Accepted Answer
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
yv = interp1(x, y, xv) % Interpolate 'y' Vector
dydxv = interp1(x, dydx, xv) % Interpolate Derivative Vector
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')
.
0 Comments
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!