Extropolate backwards for the curve

4 views (last 30 days)
Qiujun Xu
Qiujun Xu on 24 Feb 2022
Answered: Saarthak Gupta on 22 Dec 2023
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 Comments
KSSV
KSSV on 24 Feb 2022
The black line is a striaght line....pick the extreme points and use polyfit with degree 1.
Qiujun Xu
Qiujun Xu on 24 Feb 2022
Thanks for your quick answer. Do you have an idea how to pick the extreme point(cross over point) in the black line?

Sign in to comment.

Answers (1)

Saarthak Gupta
Saarthak Gupta on 22 Dec 2023
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

Categories

Find more on Linear and Nonlinear Regression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!