Finding slope of a curve at some specific points

94 views (last 30 days)
Hi.
I did the sediment settling experiment and obtained the experimental data. My task is to calculate the average particle velocity. To compute this, I must calculate the average gradient of multiple gradients at different points. Can I know how to do this?

Accepted Answer

Star Strider
Star Strider on 17 Apr 2023
Probably the easiest way to calculate the instantaneous slope is:
dydx = gradient(y) ./ gradient(x);
All that is necessary after that is to index into it by using the index of the appropriate ‘x’ values if those are known.
If the gradient is monotonic (either increasing or decreasing), it is straightforward to get the slope at any ‘x’ value using the interp1 function:
slope_at_xval = interp1(x, dydx, xval);
If the slopes are not monotonic, this is still possible, however the code becomes a bit more complicated.
.
  10 Comments
Prasanna Routray
Prasanna Routray on 3 Dec 2024
Edited: Image Analyst on 3 Dec 2024
You are a star as always.
Here is what I tried and it works.
load curveData.mat;
x = curveData(1,:);
y = curveData(2,:);
dydx = gradient(y) ./ gradient(x);
idx=450;
xv = x(idx);% Choose A Random Point
yv = interp1(x(idx:idx+1), y(idx:idx+1), xv); % Interpolate 'y' Vector
dydxv = interp1(x(idx:idx+1), dydx(idx:idx+1), xv); % Interpolate Derivative Vector
angleSlope = atand(dydxv);
if angleSlope<0
angleSlope = angleSlope + 180;
end
figure
plot(x, y)
hold on
plot(xv, yv, '*r')
hold off
text(xv, yv, sprintf(' \\leftarrow Slope at (%.3f, %.3f) = %.3f',xv, yv, angleSlope), 'Horiz','left', 'Vert','middle')
axis([-50 50 -20 220]); % Ensure equal scaling on both axes

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 3 Dec 2024
Wouldn't the average velocity just be the total displacement divided by the total time? I don't see why you need to compute the slope at a bunch of points along the curve and then average them together. That seems like the hard way of doing it.

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!