adjusting the peak of a spline in curve fitting
조회 수: 6(최근 30일)
표시 이전 댓글
Salma fathi 2023년 2월 7일
댓글: Salma fathi 2023년 3월 27일
I am trying to fit a part of a curve using smothing splines. I am using three main points. two end points and one peak point as shown in the image below. I would like to have the peak of the constructed polynomial to concide exactly on the peak point (marked in the blue circle), and not just for the fitted curve to pass through it. with the assumption that the two end point will still be fixed. any idea how this can be done?
Here i the code I am using with the data xx and yy attached
sp = spapi(k,xx,yy);
댓글 수: 1
John D'Errico 2023년 2월 7일
편집: John D'Errico 2023년 2월 7일
Um, you are not being very clear here, probably because you don't totally appreciate what you are asking. Certainly you have not been clear.
If the function must pass exactly through that peak, AND it must attain its maximum at that point, then you know unequivocably that the derivative of the function is zero at that point.
It also appears, since you have given us only a file with three data points, that the curve must also pass exactly through those other points too? So then what does this have to do with a smoothing spline? For example, it is trivial to find a cubic polynomial that satisfies your goals.
format long g
That is all the information you have shown us.
First, you cannot force a smoothing spline, as built by spapi to have the properties you wish. However, it is trivial to find the unique cubic polynomial that does have those properties. If a polynomial is defined as:
y = a*x^3 + b*x^2 + c*x + d
then you can simply formulate a set of 4 linear equations in those four unknowns. We can write it as:
A = [[xx.^3,xx.^2,xx,ones(3,1)];[3*xx(2).^2,2*xx(2),1,0]];
rhs = [yy;0];
abcd = (A\rhs)' % solve using backslash
Those are the coefficients of the unique cubic polynimal that passes through those three points, AND has a maximum at the center point. We can plot the points and that function to show you it does as required.
xint = linspace(xx(1),xx(3),500);
No smoothing spline required. Of course, my guess is, you really have more data, and you have decided to give us only three points. Even so, you still cannot force spapi to do what you wish it to do.
댓글 수: 4
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!