spline error: The first input must contain unique values.
6 ビュー (過去 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!