error using spline: The first input must contain unique values.
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Bruno Luong
el 10 de Abr. de 2024
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).
Respuestas (2)
Bruno Luong
el 9 de Abr. de 2024
Editada: Bruno Luong
el 9 de Abr. de 2024
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 comentarios
Bruno Luong
el 9 de Abr. de 2024
Editada: Bruno Luong
el 9 de Abr. de 2024
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
el 9 de Abr. de 2024
Editada: Bruno Luong
el 9 de Abr. de 2024
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 comentarios
Ver también
Categorías
Más información sobre Splines en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!