error using spline: The first input must contain unique values.
조회 수: 16 (최근 30일)
이전 댓글 표시
i am using spline function and its showing error message: The first input must contain unique values.
i am running matlab code for the initial geometry of the semicircular curved beam. When same code is run for quarter circular beam, spline is not showing any error.
How can I proceed ?
%x represents all the gauss quadrature points on the beam which are already calculated.
%initial geometry
th = linspace(pi/2, -pi/2, ng); %semicircle beam
R = 1; % radius
x = R*cos(th) ;
y = R*sin(th)+1;
plot(x,y); axis equal;
theta = spline(x,dd(y),1); %calculating the end point slope of the beam .
% dd function is created for numerical differentiation
I can provide other parts of code if required.
댓글 수: 3
Bruno Luong
2024년 4월 10일
What is wrong? I keep saying that
- you cannot call spline on x since what ever the second argument i is not a function of x.
- The end points has x = 0 in your example (cos(p/2) and cos(-pi/2), why you call spline with 1 as query point? It is not the end point.
- If you already have dd(y), from your own word it's already a slope, then you already have a slope at all the x points, includng the end point. Whar is the purpose of calluing spline that only make INTERPOLATION of whatever you have provided as second input, meaning dd(y).
답변 (2개)
Bruno Luong
2024년 4월 9일
편집: Bruno Luong
2024년 4월 9일
You did not post your spline command, my guess is you do spline(x,y)
Try to remove the last (or the first value of th, then do the rest
th = linspace(pi/2, -pi/2, ng); %semicircle beam
th(end) = [];
% ...
Or better do the before last two commands before callinfg splie(x,y)
This will fix the error but I doubt it will do what you want. Please see mu othe answer
tt = linspace(-pi,pi);
x = cos(tt);
y = sin(tt);
% spline(x,y); % error
[xu,~,J] = unique(x);
yu = accumarray(J(:), y(:), [], @mean);
s = spline(xu, yu);
댓글 수: 2
Bruno Luong
2024년 4월 9일
편집: Bruno Luong
2024년 4월 9일
At the glance your math/code looks strange to me.
My comment still applies: you cannot use spline on parametric data by ignoring the parameter (here th). The second argument dd(y) MUST implicitly be a function of the first argument (x).As x turns around each y has 2 branches values for each x. This is NOT a function.
Bruno Luong
2024년 4월 9일
편집: Bruno Luong
2024년 4월 9일
Your spline command wouldn't do what you want, since for every x you have made corresponding two y values. It is NOT a function of x; so it cannot be represented/approximated by spline function/
You better call twice spline! x wrt tt and y wrt to tt.yi
ng = 7;
th = linspace(pi/2, -pi/2, ng); %semicircle beam
R = 1; % radius
x = R*cos(th) ;
y = R*sin(th)+1;
plot(x,y,'o-.'); axis equal;
ti = linspace(min(th),max(th));
xi = spline(th,x,ti);
yi = spline(th,y,ti);
hold on
plot(xi,yi);
legend('data','spline interpolation')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!