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
KSSV 2022-2-24
The black line is a striaght line....pick the extreme points and use polyfit with degree 1.
Qiujun Xu
Qiujun Xu 2022-2-24
Thanks for your quick answer. Do you have an idea how to pick the extreme point(cross over point) in the black line?

请先登录,再进行评论。

回答(1 个)

Saarthak Gupta
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:
  1. 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.
  2. 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

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by