No BSD License  

Highlights from
polyfitweighted

3.0

3.0 | 2 ratings Rate this file 15 Downloads (last 30 days) File Size: 2.13 KB File ID: #13520

polyfitweighted

by Salman Rogers

 

29 Dec 2006 (Updated 02 Jan 2007)

Simple function to calculate a polynomial best fit of 1D data Y with array of weights W (which must

| Watch this File

File Information
Description

Like polyfit.m but includes weighting of each data point.

Summary
----------------
Find a least-squares fit of 1D data y(x) with an nth order polynomial, weighted by w(x).

Usage
-----

P = polyfitweighted(X,Y,N,W) finds the coefficients of a polynomial P(X) of degree N that fits the data Y best in a least-squares sense. P is a row vector of length N+1 containing the polynomial coefficients in descending powers, P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1). W is a vector of weights. Vectors X,Y,W must be the same length.

Class support for inputs X,Y,W:
    float: double, single

By SS Rogers http://ssr.phy.umist.ac.uk

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
02 Jan 2007 John D'Errico

Not bad. Uses a reasonable algorithm for estimation, although there is no real reason to use qr here if you do not intend to return parameter standard errors. Backslash should be appropriate here.

A minor point - why test for events that cannot possibly happen? For example why have a test for nargout>2, if there is only ONE output argument? The answer is the author has just copied the polyfit code including comments, and then modified it. I'd suggest that attribution would be nice when you copy code. At least clean it up.

I've chosen not to give any numerical rating to avoid any appearance of a conflict of interest (polyfitn also offers polynomial modeling.) But were I to offer a rating, it would not be a bad one.

04 Jan 2007 Antoni J. Canós Marín

Have you seen the submitted function polyfit3.m (File Id. 4262)?

19 Jan 2007 Salman Rogers

Thank you to John D'Errico for his comment - yes, this script is based on polyfit.m by The Mathworks which implements a well known algorithm. I have only added the weighting factor, and taken out the return of standard errors. polyfit.m is indeed acknowledged inside the file and in "help polyfitweighted". Apologies for any ambiguity.

19 Aug 2009 Matt J

In the help comments for polyfitweighted2, it says that Z and W should be of size [length(X) length(Y)]

However, throughout the code (both polyfitweighted2 and polyval2, Z and W are treated as though of size
 [length(Y) length(X)].

12 Oct 2011 S

Exactly what i was looking for

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
optimization Salman Rogers 22 Oct 2008 08:54:44
leastsquares Salman Rogers 22 Oct 2008 08:54:44
polymonial Salman Rogers 22 Oct 2008 08:54:44
best Salman Rogers 22 Oct 2008 08:54:44
fit Salman Rogers 22 Oct 2008 08:54:44
weighted Salman Rogers 22 Oct 2008 08:54:44
weights Salman Rogers 22 Oct 2008 08:54:44

Contact us at files@mathworks.com