I need help with cubic splines containing pre existing conditions
1 次查看(过去 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 个评论
回答(2 个)
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])
subs(y1,absol)
subs(y2,absol)
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 个评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!