spline error: The first input must contain unique values.

5 visualizaciones (últimos 30 días)
Stefi
Stefi el 29 de Mayo de 2024
Editada: Stefi el 30 de Mayo de 2024
I am defining a semicircle profile and then finding the x and y coordinate using interpolation at gauss legendres points
r = 0.35;
theta= linspace(pi/2,-pi/2,51);
xq = r*cos(theta);
yq = r*sin(theta)+r;
L = max(xq);
xn = xq/L;
x = spline(xn,xq,xx); %xx are gauss legendres quadrature points along x axis
y = spline(xq,yq,x);
while running the code it is showing error :Error using chckxy
The first input must contain unique values.
Error in spline
[x,y,sizey,endslopes] = chckxy(x,y);
x = spline(xn,xq,xx);
since the profile is semi circle there is duplicate x coordinates. how do i solve this error ?

Respuestas (1)

Ganesh
Ganesh el 30 de Mayo de 2024
Hi @Stefi,
I undestand that you're encountering is due to the nature of the semi-circle profile you're defining. In the semi-circle, for every x-coordinate, apart from the ends, there are two corresponding y-values.
This violates the assumption made by the "spline()" function that for each x-value there should be a unique y-value, and hence you are getting the error.
You can solve this problem by splitting your "semi-circle" into two halves, an "upper half" and a "lower half" by splitting with appropriate values of theta. Once split, you can interpolate the two halves individually and then combine them if necessary. Please find the code attached below for the same:
r = 0.35;
theta= linspace(pi/2,-pi/2,51);
xq = r*cos(theta);
yq = r*sin(theta)+r;
L = max(xq);
xn = xq/L;
xx_normalized = xx / L; % Assuming xx is already present
% Split the semi-circle into upper and lower halves
upper_half_mask = theta <= 0;
lower_half_mask = theta >= 0;
% Upper half
xq_upper = xq(upper_half_mask);
yq_upper = yq(upper_half_mask);
xn_upper = xn(upper_half_mask);
% Lower half
xq_lower = xq(lower_half_mask);
yq_lower = yq(lower_half_mask);
xn_lower = xn(lower_half_mask);
% Interpolate separately for upper and lower halves
y_upper = spline(xn_upper, yq_upper, xx_normalized);
y_lower = spline(xn_lower, yq_lower, xx_normalized);
Kindly note that you might need to ensure that xx_normalized only contains values within the range of xn_upper and xn_lower
Hope this helps!
  1 comentario
Stefi
Stefi el 30 de Mayo de 2024
Editada: Stefi el 30 de Mayo de 2024
i have to further use x and y to find slopes, curvature and other term in many other fnctions already made.
then all the functions will require a lot of changes. is there any other way ?

Iniciar sesión para comentar.

Categorías

Más información sobre Splines en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by