How to make a polyfit with constraints to the first and second derivative?

I want to make a polyfit of some data. The start and end point, and also the derivative and second derivative in begin and endpoint are knowns, how do I make a polyfit, which fulfills to this needs?
I found a polyfix, function, where you can give constraints to the start and end point, and also the derivative, but you cannot add a constraint to the second derivative. Is there another solution?
This is the link to the polyfix function: https://nl.mathworks.com/matlabcentral/fileexchange/54207-polyfix-x-y-n-xfix-yfix-xder-dydx

 Accepted Answer

More often than not, if you have such constraints, it is spline that you want to fit, not a polynomial. Constrained spline fits can be done with this FEX download:

2 Comments

I already tried the slm function. I need a polynomial function of at least degree 5, and this function can only fit functions of degrees 1,2 and 4.
Yes, but they are splines. An order 4 spline is much more flexible than a degree five polynomial.

Sign in to comment.

More Answers (1)

Well they are just linear constraints on the coefficients, so you could use lsqlin if you have the Optimization Toolbox.

Categories

Products

Release

R2022b

Asked:

on 9 May 2023

Commented:

on 9 May 2023

Community Treasure Hunt

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

Start Hunting!