How to use a spline for double values of y?

10 views (last 30 days)
How can I use a spline to fit a list of points that has double values for each x-coordinate?77 For example, at the x=0 coordinate, I have y=0.2 and y=0.4 (it is a sort of ellipsis).
  1 Comment
arich82
arich82 on 7 Oct 2015
Edited: arich82 on 7 Oct 2015
This data would represent the most degenerate sort of ellipse imaginable, with major axis a=0.2, and minor axis b=0, i.e. a vertical line:
If you have additional points, you might try converting your x-y (cartesian) coordinates to th-r (polar) coordinates, then performing a spline fit to the polar data (and finally converting back to cartesian after interpolating, assuming that is you goal). This might require shifting your x-y data to be centered around the origin to ensure that theta is unique and strictly increasing.
However, if all you have are two data points 180-degrees apart, you're never going to get anything but a straight line without some additional information about the properties of the ellipse.
In order to get more help, you're going to need to post some additional information, either a larger sample of your data, or additional parameters for the ellipse. If you truly have only two data points 180-degrees apart, then I'm afraid your desired solution might not exist...
(Lastly, if you know the data obeys an ellipse, why not just try to find the best-fit ellipse equation instead of using a spline fit?)

Sign in to comment.

Answers (1)

Alessandro Orchini
Alessandro Orchini on 31 Mar 2017
Suppose you have the ellipsis defined by:
N = 20;
dt = 2*pi/N;
theta = 0:dt:2*pi;
x = 0.5*cos(theta);
y = 0.1*sin(theta);
Assuming your points are already ordered, you can define two functions, one for the x values and one for the y values, as functions of the points indexes. These are single-valued functions (it is an arclength representation) and can be fitted onto splines.
splX = spline(1:length(x),x,1:0.1:length(x));
splY = spline(1:length(y),y,1:0.1:length(y));
figure(1)
clf
plot(splX,splY,'k-')
hold on
plot(x,y,'r.')
hold off
If your points are not ordered, you will need to order them before fitting, by starting from a certain point, looking for the closest neighbour, and iterating.
  1 Comment
Junkyu Ham
Junkyu Ham on 18 Apr 2023
You are amazing.. I try to solve this problem for 2 weeks............ now i'd been solved it. thank you.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!