How to use a spline for double values of y?

11 vues (au cours des 30 derniers jours)
Alessandro  Perez
Alessandro Perez le 7 Oct 2015
Modifié(e) : Torsten le 29 Mai 2024
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 commentaire
arich82
arich82 le 7 Oct 2015
Modifié(e) : arich82 le 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?)

Connectez-vous pour commenter.

Réponses (1)

Alessandro Orchini
Alessandro Orchini le 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.
  3 commentaires
Stefi
Stefi le 29 Mai 2024
Modifié(e) : Stefi le 29 Mai 2024
i am doing a similar kind of thing . how will I use the above method in my code to get the answer?
i have x and y cooridnates of semicircle and slopes at each point of evaluation. I want to generate the slope at end point using spline but it is showing same error .
theta = linspace(pi/2, -pi/2, 20);
R = 0.5;
x = R*cos(theta) ;
y = R*sin(theta);
slope= slp(y); % slp is a function made for calculating slope
slope_at_end = spline(x,slp(y),1);
Torsten
Torsten le 29 Mai 2024
Modifié(e) : Torsten le 29 Mai 2024
Here is the spline structure. Now you need to tell is where you want the slopes to be evaluated:
theta = linspace(pi/2, -pi/2, 20);
R = 0.5;
x = R*cos(theta) ;
y = R*sin(theta);
pp = cscvn([x;y])
pp = struct with fields:
form: 'pp' breaks: [0 0.2874 0.5747 0.8621 1.1495 1.4368 1.7242 2.0116 2.2989 2.5863 2.8737 3.1610 3.4484 3.7358 4.0231 4.3105 4.5979 4.8852 5.1726 5.4600] coefs: [38x4 double] pieces: 19 order: 4 dim: 2
fnplt(pp)
axis equal
xlim([0 0.5])
ylim([-0.5 0.5])

Connectez-vous pour commenter.

Catégories

En savoir plus sur Splines dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by