spline error: The first input must contain unique values.
조회 수: 4 (최근 30일)
이전 댓글 표시
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 ?
댓글 수: 0
답변 (1개)
Ganesh
2024년 5월 30일
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!
참고 항목
카테고리
Help Center 및 File Exchange에서 Splines에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!