I need help with cubic splines containing pre existing conditions

2 次查看(过去 30 天)
My spline passes through (0,0), (1,1),and (2,2), but also S0’(0)=S1’(2)=1, I don’t know how to implement this last condition, my coefs don’t fit this criteria, so I know they’re wrong
  2 个评论
Torsten
Torsten 2023-11-19
编辑:Torsten 2023-11-19
s(x) = x
Show us your linear system that you use to determine the spline coefficients.
Leo Fischer
Leo Fischer 2023-11-20
So, my Sn = {S0 = a0(x-x0)^3 + b0(x-x0)^2 + c0(x-x0) + d0
D0 = S0(x0) = y0 B0 = s0’’(x0)/2 And then I just go around the clamped properties to find out the other values, was that what you were asking?

请先登录,再进行评论。

回答(2 个)

John D'Errico
John D'Errico 2023-11-19
编辑:John D'Errico 2023-11-19
Easy enough. And ... also somewhat useless, because this is not how you will have been asked to solve the problem. But it might give you an idea of what you missed. And that is what I want you to do, to think about the problem, and what you did.
a = sym('a',[1,4])
b = sym('b',[1,4]);
syms x real
y1(x) = dot(x.^(3:-1:0),a);
y2(x) = dot(x.^(3:-1:0),b);
dy1 = diff(y1,x);
dy2 = diff(y2,x);
ddy1 = diff(dy1);
ddy2 = diff(dy2);
absol = solve(y1(0) == 0,y1(1) == 1,y2(1) == 1, y2(2) == y1(2),dy1(0) == 1,dy2(2) == 1,dy1(1) == dy2(1),ddy1(1) == ddy2(1),[a,b])
absol = struct with fields:
a1: 0 a2: 0 a3: 1 a4: 0 b1: 0 b2: 0 b3: 1 b4: 0
subs(y1,absol)
ans(x) = 
x
subs(y2,absol)
ans(x) = 
x
The cubic spline is now easily seen to be that which @Torsten suggested. Note that I have used an absolute form for the polynomial segments, not a relative one, as tools like spline will do.
What did you do wrong? Take a careful look at the constraints I posed in the call to solve. Now think about what is missing or incorrect in the code you wrote.
  2 个评论
Leo Fischer
Leo Fischer 2023-11-20
Basically, my spline had to follow those three points I mentioned, but when it came to that derivative part, my c0 = 0,5, when it had to be equal to 1, but then, when I used the same code for the other stuff I had to do, it worked perfectly. I guess it might have been something about the order I was inputting my code, I’ll try to revise some more before updating you
John D'Errico
John D'Errico 2023-11-20
编辑:John D'Errico 2023-11-20
All I can suggest is to be more careful about how you implemented the various conditions. Look very carefully at what you wrote, since you show no code at all for us to see. Having written splines code that have been used an uncountable number of times, I can say that it will work, but that you need to do it right.
If I had to guess, it is that you computed a derivative incorrectly, so that it works on some specia lcase, but it fails otherwise.

请先登录,再进行评论。


Matt J
Matt J 2023-11-19
编辑:Matt J 2023-11-19
e=0:2;
xq=linspace(0,2,20);
yq=spline(e,[1,e,1],xq);
plot(e,e,'o',xq,yq,'.'); legend('Control Points','Interpolated','Location','southeast')

类别

Help CenterFile Exchange 中查找有关 Splines 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by