Finding slope of a curve at some specific points

60 vues (au cours des 30 derniers jours)
Sein Lim
Sein Lim le 17 Avr 2023
Modifié(e) : Image Analyst le 3 Déc 2024
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?

Réponse acceptée

Star Strider
Star Strider le 17 Avr 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 commentaires
Prasanna Routray
Prasanna Routray le 3 Déc 2024
Modifié(e) : Image Analyst le 3 Déc 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
Star Strider
Star Strider le 3 Déc 2024
My pleasure!
A Vote would be appreciated!

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 3 Déc 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.

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by