Give this a try and let us know what you think here or leave a comment for Are. g fittype ( (a, b, x) ax.2+bx+c ) Here, the value of c is fixed when you create the fit type. To pass in new data from the workspace, recreate the fit type, e.g., c 5 Change value of c. If you need other sophisticated constraints, you would want to check out Optimization Toolbox. The fittype function can use the variable values in your workspace when you create the fit type. norm(x_lsqlin2-x_polyfix')Īre's polyfit is great for performing polynomial fits with constraints around passing points. If we compare this result with that from lsqlin, we see that it's essentially identical. Set(gca, 'XTick',0:0.5:2) % Adjust tick marks to show points of interest x_polyfix = Let's solve the same problem using polyfix, 7th order polynomial to fit through (0,0), (2,0), (0.5,1), (1.5,-1) and derivative of zero at $t$ = 0.5 and $t$ = 1.5. This entry achieves the goal of performing a polynomial fit with constraints to pass through specific points with specific derivatives. In the MATLAB Answers post I mentioned above, Are actually posted a response mentioning polyfix. Set(gca, 'XTick',0:0.5:2) % Adjust tick marks to show points of interest Warning: The trust-region-reflective algorithm can handle bound constraints Legend( 'data', 'lsqlin (with derivative constraint)') Let's fit and see if we've accomplished our goal. lsqlin solves the following least-squares curve fitting problem. There are several ways to deal with this, and one of them is to use a function like lsqlin from Optimization Toolbox. But first, let me talk about a different method. This is where Are's entry comes into play. Perhaps, you want the curve to cross (0, 0) and (2, 0). What if you want this polynomial to go through certain points. We'll fit a 3rd order polynomial to the data. The function polyfit lets you fit a polynomial to your data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |