Message Boards Message Boards

Fitting a c-shaped curved with right-pointing parabola, ellipse or circle

Posted 11 months ago

Hi everyone,

I was trying to fit the following points:

ListPlot[points]

enter image description here

The objective is to reach a function that fits the points, something similar to this: enter image description here

In my understanding, this looks like a right-pointing parabola:

enter image description here right-pointing parabola

So I tried this function, but it didn't work (the fit was inaccurate):

curveFit= Plot[57.01032231556321` +4.524767722795246` *(-29.0814390274144`+x)^2,{x,28,29.33},PlotStyle->Orange]; 

Show[points, curveFit]

enter image description here

So I decided to try to fit an ellipse or circle instead, but I don't know how to do it in an automated way(maybe like a Monte Carlo simulation). so I drew an ellipse on top of the points:

h=29.01(*x-coordinate of the center*);
k=57.175(*y-coordinate of the center*);
a=0.13(*radius along the x-axis*);
b=0.2(*radius along the y-axis*);
ellipse = ParametricPlot[{h+a Cos[t],k+b Sin[t]},{t,0,2 Pi},PlotRange->All,AxesLabel->{"x","y"},AxesOrigin->{h-a,k-b},PlotStyle->Orange]

Show[ellipse, points]

enter image description here

I hope anyone can guide me on the right way to proceed. Thanks in advance.

POSTED BY: Mario F
8 Replies
Posted 11 months ago
Posted 11 months ago

I am the one who posted it there as well :) because I was desperate for a reply. Not sure if it was the right thing to do. I am new to the platform.

POSTED BY: Mario F
Posted 11 months ago

I don't have a problem with posting things simultaneously but you really need to give the associated links in each post. Otherwise, suppose at one post someone answers the question. Then at the other post you're wasting folks limited time because the question has already been answered. Or there might be a comment or partial answer that allows someone on another site to give a complete answer if they knew to look where you've also posted the same question.

POSTED BY: Jim Baldwin

Mario, here is one way:

(* generation of similar data: *)
dd = .1;
data = Table[{2 + x^2 + RandomReal[{-dd, dd}], x + RandomReal[{-dd, dd}]}, {x, -2, 2, .1}];
(* working on x- and y-component seperately: *)
{datax, datay} = Transpose[data];
(* we then have: *)
ListPlot[{datax, datay}]

enter image description here

(* this then can be fitted in a regular way: *)
modelx = x2 t^2 + x1 t + x0;
modely = y1 t + y0;
paramsx = FindFit[datax, modelx, {x0, x1, x2}, t];
paramsy = FindFit[datay, modely, {y0, y1}, t];
func[t_] = ({modelx, modely} /. paramsx) /. paramsy;
ParametricPlot[func[t], {t, 1, Length[data]}, Epilog -> {Red, Point[data]}]

enter image description here

Does that help? Regards -- Henrik

POSTED BY: Henrik Schachner
Posted 11 months ago

Thank you so much Henrik. I will try it and let you know.

POSTED BY: Mario F
Posted 11 months ago

I have two updates:

I was able to fit equations in this link as follows:

enter image description here

Also, I discovered that I can use the drawing tool to draw ellipses on the points and then convert the cell with the plot (without the original) to input, then it will give the equation for the ellipse in terms of Graphics[Circle[{29.009734682576344, 57.18617339634879}, {0.12473528321493177, 0.2126919292376499}]]

But still, these two approaches are not the "best fit", it just a better guess.

POSTED BY: Mario F
Posted 11 months ago

Can you supply more specifics about your objective in "fitting" ? Here are some examples:

  • If the objective is to provide a curve that is an approximation of the the data with a formula (parabola, ellipse, or something else), how close must that approximation be?

  • If the objective is to predict future points, what is the mechanism for generating the current data and future data?

  • If the objective is "I'll know it when I see it", then know that we can't read your mind. I say this because of your statement "But still, these two approaches are not the 'best fit', it just a better guess."

POSTED BY: Jim Baldwin
Posted 11 months ago

Well thank you for your questions they helped me to think better about my objective.

The motion is a rotation of a robot about a center point. But there is an error that's why this ellipse is formed. i.e. it should be a point rather than an ellipse.

The data source is from sensor position data, then it is transformed using a transformation matrix to the center.

The objective is to predict the error so I would predict the motion without relaying on the sensor, just the difference between angles.

POSTED BY: Mario F
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract