4.83333

4.8 | 6 ratings Rate this file 78 downloads (last 30 days) File Size: 19.9 KB File ID: #13719

2D Weighted Polynomial Fitting and Evaluation

by Salman Rogers

 

19 Jan 2007 (Updated 12 Feb 2007)

No BSD License  

Two scripts: polyfitweighted2 fits 2D data with weights, and polyval2 evaluates the 2D polynomial

Download Now | Watch this File

File Information
Description

polyfitweighted2.m and polyval2.m
---------
polyfitweighted2.m: Find a least-squares fit of 2D data z(x,y) with an n th order polynomial, weighted by w(x,y).

polyval2.m: Evaluate 2D polynomial produced by polyfitweighted2.m.

Usage polyfitweighted2
-----
P = polyfitweighted2(X,Y,Z,N,W) finds the coefficients of a polynomial P(X,Y) of degree N that fits the data Z best in a least-squares sense. P is a row vector of length (N+1)*(N+2)/2 containing the polynomial coefficients in ascending powers, 0th order first.

 P = [p00 p10 p01 p20 p11 p02 p30 p21 p12 p03...]

where pNM is the polynomial coefficient of the Nth power of X times the Mth power of Y.

based on polyfit.m by The Mathworks Inc.

For more information see HTML-published M-file included.

Note: P is not in the format of standard Matlab 1D polynomials. Use polval2.m to evaluate the polynomial in this format, at given values of x,y.

Usage polyval2
---
Z = POLYVAL2(P,X,Y) returns the value of a 2D polynomial P evaluated at (X,Y). P is a vector of length (N+1)*(N+2)/2 containing the polynomial coefficients in ascending powers as above.

MATLAB release MATLAB 7.3 (R2006b)
Zip File Content  
Published M Files polyfitweighted2.m and polyval2.m
Other Files polyfitweighted2/polyfitweighted2.m,
polyfitweighted2/polyval2.m,
polyfitweighted2/publishpolyfitweighted2.png,
polyfitweighted2/publishpolyfitweighted2_01.png
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
11 Feb 2007 Ron Abileah  
20 Nov 2007 Eric Lin

Thank you!

12 Dec 2007 Feng Liu

Good work!

16 Jun 2009 Andrey Rubshtein

Dear Salman, first of all thank you for your submission.
Nevertheless, I have a minor remark - In many applications (x,y,z) triples are not necessarily measured on a grid. For example: I have:
(1,1,10), (1,2,5) , (2,1,7) , but i have no clue what is the value of z at (2,2).

25 Jun 2009 Ryan Kruse

This is great! Thanks!

I made a slight modification to deal with NaN values. I changed this:
x = x(:);
y = y(:);
z = z(:);
w = w(:);

to this:
x = x(~isnan(z));
y = y(~isnan(z));
z = z(~isnan(z));
w = w(~isnan(z));

04 Aug 2009 K E

Very useful. Matlab should build it in.

Please login to add a comment or rating.
Updates
12 Feb 2007

minor edit to improve discription

Tag Activity for this File
Tag Applied By Date/Time
statistics Salman Rogers 22 Oct 2008 08:57:50
probability Salman Rogers 22 Oct 2008 08:57:50
2d Cristina McIntire 15 Jan 2009 13:43:32
fitting evaluation Cristina McIntire 15 Jan 2009 13:43:32
polynomial Cristina McIntire 15 Jan 2009 13:43:32
weighted Cristina McIntire 15 Jan 2009 13:43:32
weighted Richard Voigt 18 May 2009 13:52:17
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com