Finding slope of a curve at some specific points

96 Ansichten (letzte 30 Tage)
Sein Lim
Sein Lim am 17 Apr. 2023
Bearbeitet: Image Analyst vor etwa 18 Stunden
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?

Akzeptierte Antwort

Star Strider
Star Strider am 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 Kommentare
Prasanna Routray
Prasanna Routray am 3 Dez. 2024 um 4:44
Bearbeitet: Image Analyst vor etwa 18 Stunden
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
Star Strider
Star Strider vor etwa 18 Stunden
My pleasure!
A Vote would be appreciated!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 3 Dez. 2024 um 5:12
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.

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by