Placing restrictions on spline fits

3 次查看(过去 30 天)
I am trying to use the spline function to get a fit for a set of data. My problem is that I need to specify the value for the local minima and I have not been able to find a way to accomplish this. An example code would be what is shown below:
x = -180:90:180;
y = [10 5 1 6 10]
cs = spline(x,[0 y 0]);
xx = linspace(-180,180,181);
yy = ppval(cs,xx);
plot(x,y,'o',xx,yy,'-');
I need to be able to specify that the local minima be 1, but the fit dips below that. I could do this by specifying the x-value for zero slope as well. Please point me in the direction of a function or tool that will allow me to do this. I have tried a few spline fits and pchip, but haven't gotten the curve fitting toolbox yet because I don't want to spend the money if it won't help. It must also be able to be periodic, that is the slope at the endpoints must also be zero.
Thanks

采纳的回答

José-Luis
José-Luis 2013-5-20
编辑:José-Luis 2013-5-20
I don't think you can set a minimum for the y-values, at least not automagically. What you can do, however, is to specify a slope at the ends (left and right) of your spline. You could then split your data in two sets, one with x inferior to zero and one with x superior to zero and fit a spline on both sides, such that the slope to the left and right of zero is equal to zero. For your data, that should prevent it to dip below zero.
The problem would be that you would only have three points to which to fit the spline, and in this case the results look very much like straight lines.
x = -180:90:180;
y = [10 5 1 6 10]
cs = spline(x,[0 y 0]);
xx = linspace(-180,180,181);
yy = ppval(cs,xx);
plot(x,y,'o',xx,yy,'-'); hold on
test_left = csape(x(1:3),y(1:3),[0 0]);
test_right = csape(x(3:5),y(3:5),[0 0]);
y_left = ppval(test_left,xx(1:91));
y_right = ppval(test_right,xx(91:181));
plot(xx(1:91),y_left,'g--',xx(91:181),y_right,'g--');
And you would need the curve fitting toolbox, I'm afraid.
  2 个评论
Henry McCabe
Henry McCabe 2013-5-20
编辑:Henry McCabe 2013-5-20
Thanks for the help, I never thought of that.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by