MATLAB -- how to create a parabolic arc?

Example, I have three points x1, x2, and x3.
x1 is the start point of the arc; x3 is the end point of the arc; x2 is the critical point of the arc (where the tangent slope is zero).
If x2<x1, then the arc is a U-shaped (smiley); If x2>x1, then the arc is a upside-down-U-shaped (upside smiley).
Any ideas?

1 Comment

Youssef  Khmou
Youssef Khmou on 15 Apr 2013
Edited: Youssef Khmou on 15 Apr 2013
that condition is done automatically by the equation ax²+bx+c

Sign in to comment.

 Accepted Answer

Youssef  Khmou
Youssef Khmou on 15 Apr 2013
Edited: Youssef Khmou on 15 Apr 2013
hi,
The parabola's equation is defined y=ax²+bx+c, you need to set the coefficients a,b,and c so as the line passes through the three points x1,x2 and x3 :
x1=[0,0];
x2=[5,5];
x3=[10,0];
Y=[x1(2);x2(2);x3(2)]
A=[x1(1)^2 x1(1) 1;x2(1)^2 x2(1) 1;x3(1)^2 x3(1) 1]
X=inv(A)*Y
x=x1(1):0.1:x3(1);
Y=X(1)*x.^2+X(2)*x;
figure, plot(x,Y), grid on,
hold on
text(x1(1),x1(2), ' POINT X1')
text(x2(1),x2(2), ' POINT X2')
text(x3(1),x3(2), ' POINT X3')
hold off

5 Comments

You're a godsend!
One thing, could you explain Line 4 -> Line 8?
Youssef  Khmou
Youssef Khmou on 15 Apr 2013
Edited: Youssef Khmou on 15 Apr 2013
initial conditions,
at point 1 :
y1= a * x1^2 + b *x1 + c
at point 2
y2= a * x2^2 + b *x2 + c
at point 3 :
y3= a * x3^2 + b *x3 + c
Re-arrange :
y1= a * x1^2 + b *x1 + c
y2= a * x2^2 + b *x2 + c
y3= a * x3^2 + b *x3 + c
three equations with 3 unknowns a,b and c so Y(y1 y2 y3) is : Y=[x1(2);x2(2);x3(2)]
the matrix A is A=[x1(1)^2 x1(1) 1;x2(1)^2 x2(1) 1;x3(1)^2 x3(1) 1]
solving linear system gives a,b,and c .
now we take x coordinate of the initial point and the x coordinate of the last point and construct the vector on which the equation will be computed : x=x1(1):0.1:x3(1); Y=X(1)*x.^2+X(2)*x;
It must be clear ok?
can you tell me, how to find the values of x if you have y values
how would you do this with the points (-15,2), (1,4), and (3,5)? I keep getting wrong y coordinates when I plot.

Sign in to comment.

More Answers (3)

Jim Riggs
Jim Riggs on 15 Feb 2018
Edited: Jim Riggs on 15 Feb 2018
This is a simple polynomial curve fit problem. If you have the curve fitting toolbox, the problem is solved by:
x = [0 5 10];
y = [0 5 0];
fit(x,y,'poly2');
This will give the coefficients for the second order polynomial. With only 3 point, the fitted curve will pass exactly through all three points. This function will work for any three points, as long as they are no colinear.
If you do not have the curve fitting toolbox, its not too hard to build a function which will perform polynomial curve fitting. If you are interested, I will help you work out the equations.
Vetrivel
Vetrivel on 30 Aug 2022
x = [0 5 10];
y = [0 5 0];
fit(x,y,'poly2');
x = [0 5 10];
y = [0 5 0];
fit(x,y,'poly2');

Categories

Community Treasure Hunt

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

Start Hunting!