Extropolate backwards for the curve
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
KSSV
il 24 Feb 2022
The black line is a striaght line....pick the extreme points and use polyfit with degree 1.
Risposte (1)
Saarthak Gupta
il 22 Dic 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:
- 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 Commenti
Vedere anche
Categorie
Scopri di più su Linear and Nonlinear Regression in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!