Finding slope of a curve at some specific points

77 visualizaciones (últimos 30 días)
Sein Lim
Sein Lim el 17 de Abr. de 2023
Editada: Image Analyst el 3 de Dic. de 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?

Respuesta aceptada

Star Strider
Star Strider el 17 de Abr. de 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 comentarios
Prasanna Routray
Prasanna Routray el 3 de Dic. de 2024
Editada: Image Analyst el 3 de Dic. de 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 el 3 de Dic. de 2024
My pleasure!
A Vote would be appreciated!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 3 de Dic. de 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.

Categorías

Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by