Post by Chon-JiI tried using this code but it just turned out like a slanted line.
My x and y are the coordinates of an object trajectory. Basically, I
know that the object follows an upward parabolic path so I think
having a parabolic curve fitting function would help improve the
accruacy.
I assigned 6 to s0 since I have 6 points in the trajectory.
s0 = 6; s1 = sum(x); s2 = sum(x.^2); s3 = sum(x.^3); s4 = sum(x.^4);
A = [s4,s3,s2;s3,s2,s1;s2,s1,s0];
d = [sum(x.^2.*y);sum(x.*y);sum(y)];
a = A\d;
y2 = a(1)*x.^2+a(2)*x+a(3);
x2 = x;
thanks
-----------------------
Could you please give the x-y coordinates of the six points that gave
you a "slanted line" result? If they lie on the path of an object's
trajectory acting under gravity, the parabola should be markedly concave
downwards. That is, a(1) should be negative.
I assumed when I gave you that code that you wanted a parabola of the
form y = a*x^2+b*x+c and in which the mean square difference between the y
values of the given points and the corresponding parabola points with the
same x value was to be a minimum. Did I assume correctly?
There are other parabola solutions possible having axes of symmetry at
orientations other than parallel to the y-axis. Also you might have
wanted to have a least mean square orthogonal distance from the points.
These would be more difficult problems.
(Remove "xyzzy" and ".invalid" to send me email.)
Roger Stafford