Extropolate backwards for the curve
조회 수: 4 (최근 30일)
이전 댓글 표시
Dear Mathworks community,
I have a question and would like to ask some help.
I have a speed profile as you could see on the picture. The speed profile is in yellow curve.
What I want to do is to fit the now acceleration after each deceleration. As you could see, the black curve would be the speed with higher acceleration. I think I know how to generate the black curve.
My question is: is that possible to generate the red curve. Bascially, to extrapolate backwards from the deceleration event, and to have cross section with black curve.
Thank you very much.
댓글 수: 2
KSSV
2022년 2월 24일
The black line is a striaght line....pick the extreme points and use polyfit with degree 1.
답변 (1개)
Saarthak Gupta
2023년 12월 22일
Hi Qiujun,
I understand you wish to fit and extrapolate the red line across critical points of yellow and black curves.
Depending on how the black curve is defined and plotted, the following cases occur:
- If the black curve has a defined closed form equation or function, it can be calculated at any specific point: Here, determine the y-value of the black curve's right endpoint by applying the function at an appropriate x-value.
- If the black curve is represented by a collection of (x,y) Cartesian coordinates: In this scenario, the endpoints of the black curve are already determined, and no further action is required.
Assuming you have the critical points of the yellow curve (where it transitions from acceleration to deceleration vice-versa), you can fit a first-degree polynomial (a linear equation) to selected points on both the yellow and black curves.
Refer to the following code for an example that fits a line to 2 given points:
% plot sin curve
xs = linspace(0,2*pi);
plot(xs,sin(xs));
% points to be evaluated
x1 = 1;
y1 = sin(x1);
x2 = 5.7;
y2 = sin(x2);
% compute line of best fit for the points
p = polyfit([x1 x2], [y1 y2], 1);
% plot the line
xsPoly = linspace(x1,x2);
hold on;
plot(xsPoly,polyval(p,xsPoly));
Refer to the following MATLAB documentation for further reference:
Hope this helps!
Best regards,
Saarthak
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!