Finding slope of a curve at some specific points
조회 수: 94 (최근 30일)
이전 댓글 표시
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1358293/image.png)
댓글 수: 0
채택된 답변
Star Strider
2023년 4월 17일
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
Prasanna Routray
2024년 12월 3일
편집: Image Analyst
2024년 12월 3일
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
추가 답변 (1개)
Image Analyst
2024년 12월 3일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!