Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: function polyfit

Subject: function polyfit

From: beda meda

Date: 14 May, 2008 19:48:02

Message: 1 of 7

Hi,
I have one vector of variable y and four vectors of x1, x2,
x3 and x4. And I need to aproximate y by least squares
method from all vectors x. Example:

y --------- x1 --------- x2 --------- x3 ---------- x4

104 ---- 145.455 ---- 446.493 ---- 1381.006 ---- 2472.230
104 ---- 142.857 ---- 415.004 ---- 1556.626 ---- 2553.037
104 ---- 145.455 ---- 540.619 ---- 1778.841 ---- 2539.434
105 ---- 150.943 ---- 405.916 ---- 1307.187 ---- 2483.152
104 ---- 142.857 ---- 420.071 ---- 1764.712 ---- 2553.209
105 ---- 142.857 ---- 445.416 ---- 1519.577 ---- 2498.646
103 ---- 148.148 ---- 316.140 ---- 1728.223 ---- 2544.723
102 ---- 148.148 ---- 372.026 ---- 1529.687 ---- 2473.594
106 ---- 235.294 ---- 361.520 ---- 1493.840 ---- 2602.597
106 ---- 228.571 ---- 427.001 ---- 1778.426 ---- 2571.960
106 ---- 235.294 ---- 434.787 ---- 1505.175 ---- 2753.895

I now this can be accomplished with function "polyfit", but
I didn't understand from help, how should I do it. Should I
make matrice from those x vectors and present that matrice
as x in "polyfit" function?

Thanks for help

Subject: function polyfit

From: richardstartz@comcast.net

Date: 14 May, 2008 19:56:59

Message: 2 of 7

On Wed, 14 May 2008 19:48:02 +0000 (UTC), "beda meda"
<b.meda@centrum.cz> wrote:

>Hi,
>I have one vector of variable y and four vectors of x1, x2,
>x3 and x4. And I need to aproximate y by least squares
>method from all vectors x. Example:
>
>y --------- x1 --------- x2 --------- x3 ---------- x4
>
>104 ---- 145.455 ---- 446.493 ---- 1381.006 ---- 2472.230
>104 ---- 142.857 ---- 415.004 ---- 1556.626 ---- 2553.037
>104 ---- 145.455 ---- 540.619 ---- 1778.841 ---- 2539.434
>105 ---- 150.943 ---- 405.916 ---- 1307.187 ---- 2483.152
>104 ---- 142.857 ---- 420.071 ---- 1764.712 ---- 2553.209
>105 ---- 142.857 ---- 445.416 ---- 1519.577 ---- 2498.646
>103 ---- 148.148 ---- 316.140 ---- 1728.223 ---- 2544.723
>102 ---- 148.148 ---- 372.026 ---- 1529.687 ---- 2473.594
>106 ---- 235.294 ---- 361.520 ---- 1493.840 ---- 2602.597
>106 ---- 228.571 ---- 427.001 ---- 1778.426 ---- 2571.960
>106 ---- 235.294 ---- 434.787 ---- 1505.175 ---- 2753.895
>
>I now this can be accomplished with function "polyfit", but
>I didn't understand from help, how should I do it. Should I
>make matrice from those x vectors and present that matrice
>as x in "polyfit" function?
>
>Thanks for help

The built-in operator "\" will do this for you.
-Dick Startz

Subject: function polyfit

From: NZTideMan

Date: 14 May, 2008 20:01:06

Message: 3 of 7

On May 15, 7:48=A0am, "beda meda" <b.m...@centrum.cz> wrote:
> Hi,
> I have one vector of variable y and four vectors of x1, x2,
> x3 and x4. And I need to aproximate y by least squares
> method from all vectors x. Example:
>
> y --------- x1 --------- x2 --------- x3 ---------- x4
>
> 104 ---- 145.455 ---- 446.493 ---- 1381.006 ---- 2472.230
> 104 ---- 142.857 ---- 415.004 ---- 1556.626 ---- 2553.037
> 104 ---- 145.455 ---- 540.619 ---- 1778.841 ---- 2539.434
> 105 ---- 150.943 ---- 405.916 ---- 1307.187 ---- 2483.152
> 104 ---- 142.857 ---- 420.071 ---- 1764.712 ---- 2553.209
> 105 ---- 142.857 ---- 445.416 ---- 1519.577 ---- 2498.646
> 103 ---- 148.148 ---- 316.140 ---- 1728.223 ---- 2544.723
> 102 ---- 148.148 ---- 372.026 ---- 1529.687 ---- 2473.594
> 106 ---- 235.294 ---- 361.520 ---- 1493.840 ---- 2602.597
> 106 ---- 228.571 ---- 427.001 ---- 1778.426 ---- 2571.960
> 106 ---- 235.294 ---- 434.787 ---- 1505.175 ---- 2753.895
>
> I now this can be accomplished with function "polyfit", but
> I didn't understand from help, how should I do it. Should I
> make matrice from those x vectors and present that matrice
> as x in "polyfit" function?
>
> Thanks for help

Polyfit's the wrong one for this.
help mldivide
Take special notice of the 2nd paragraph which talks about least
squares
coef=3D[x1 x2 x3 x4]\y

Subject: function polyfit

From: beda meda

Date: 14 May, 2008 21:05:05

Message: 4 of 7

NZTideMan <mulgor@gmail.com> wrote in message
<08bcf48a-93cf-4651-a763-b00d212b1f2d@c19g2000prf.googlegroups.com>...
> On May 15, 7:48=A0am, "beda meda" <b.m...@centrum.cz> wrote:
> > Hi,
> > I have one vector of variable y and four vectors of x1, x2,
> > x3 and x4. And I need to aproximate y by least squares
> > method from all vectors x. Example:
> >
> > y --------- x1 --------- x2 --------- x3 ---------- x4
> >
> > 104 ---- 145.455 ---- 446.493 ---- 1381.006 ---- 2472.230
> > 104 ---- 142.857 ---- 415.004 ---- 1556.626 ---- 2553.037
> > 104 ---- 145.455 ---- 540.619 ---- 1778.841 ---- 2539.434
> > 105 ---- 150.943 ---- 405.916 ---- 1307.187 ---- 2483.152
> > 104 ---- 142.857 ---- 420.071 ---- 1764.712 ---- 2553.209
> > 105 ---- 142.857 ---- 445.416 ---- 1519.577 ---- 2498.646
> > 103 ---- 148.148 ---- 316.140 ---- 1728.223 ---- 2544.723
> > 102 ---- 148.148 ---- 372.026 ---- 1529.687 ---- 2473.594
> > 106 ---- 235.294 ---- 361.520 ---- 1493.840 ---- 2602.597
> > 106 ---- 228.571 ---- 427.001 ---- 1778.426 ---- 2571.960
> > 106 ---- 235.294 ---- 434.787 ---- 1505.175 ---- 2753.895
> >
> > I now this can be accomplished with function "polyfit", but
> > I didn't understand from help, how should I do it. Should I
> > make matrice from those x vectors and present that matrice
> > as x in "polyfit" function?
> >
> > Thanks for help
>
> Polyfit's the wrong one for this.
> help mldivide
> Take special notice of the 2nd paragraph which talks about
least
> squares
> coef=3D[x1 x2 x3 x4]\y

I think this is what I need, thanks!
---------------------------

to Dick:
You meant I should divide matrice x by y and then use
polyfit? Or if not, what did you mean?

But thank you too!

Subject: function polyfit

From: richardstartz@comcast.net

Date: 14 May, 2008 21:08:19

Message: 5 of 7

On Wed, 14 May 2008 21:05:05 +0000 (UTC), "beda meda"
<b.meda@centrum.cz> wrote:

>NZTideMan <mulgor@gmail.com> wrote in message
><08bcf48a-93cf-4651-a763-b00d212b1f2d@c19g2000prf.googlegroups.com>...
>> On May 15, 7:48=A0am, "beda meda" <b.m...@centrum.cz> wrote:
>> > Hi,
>> > I have one vector of variable y and four vectors of x1, x2,
>> > x3 and x4. And I need to aproximate y by least squares
>> > method from all vectors x. Example:
>> >
>> > y --------- x1 --------- x2 --------- x3 ---------- x4
>> >
>> > 104 ---- 145.455 ---- 446.493 ---- 1381.006 ---- 2472.230
>> > 104 ---- 142.857 ---- 415.004 ---- 1556.626 ---- 2553.037
>> > 104 ---- 145.455 ---- 540.619 ---- 1778.841 ---- 2539.434
>> > 105 ---- 150.943 ---- 405.916 ---- 1307.187 ---- 2483.152
>> > 104 ---- 142.857 ---- 420.071 ---- 1764.712 ---- 2553.209
>> > 105 ---- 142.857 ---- 445.416 ---- 1519.577 ---- 2498.646
>> > 103 ---- 148.148 ---- 316.140 ---- 1728.223 ---- 2544.723
>> > 102 ---- 148.148 ---- 372.026 ---- 1529.687 ---- 2473.594
>> > 106 ---- 235.294 ---- 361.520 ---- 1493.840 ---- 2602.597
>> > 106 ---- 228.571 ---- 427.001 ---- 1778.426 ---- 2571.960
>> > 106 ---- 235.294 ---- 434.787 ---- 1505.175 ---- 2753.895
>> >
>> > I now this can be accomplished with function "polyfit", but
>> > I didn't understand from help, how should I do it. Should I
>> > make matrice from those x vectors and present that matrice
>> > as x in "polyfit" function?
>> >
>> > Thanks for help
>>
>> Polyfit's the wrong one for this.
>> help mldivide
>> Take special notice of the 2nd paragraph which talks about
>least
>> squares
>> coef=3D[x1 x2 x3 x4]\y
>
>I think this is what I need, thanks!
>---------------------------
>
>to Dick:
>You meant I should divide matrice x by y and then use
>polyfit? Or if not, what did you mean?
>
>But thank you too!

Basically, I was saying the same thing NZTide said. The coefficients
are

coef=[x1 x2 x3 x4]\y;

The approximated value is

[x1 x2 x3 x4]*coef;

Subject: function polyfit

From: John D'Errico

Date: 15 May, 2008 00:03:02

Message: 6 of 7

"beda meda" <b.meda@centrum.cz> wrote in message
<g0ffli$fv3$1@fred.mathworks.com>...
> Hi,
> I have one vector of variable y and four vectors of x1, x2,
> x3 and x4. And I need to aproximate y by least squares
> method from all vectors x. Example:
>
> y --------- x1 --------- x2 --------- x3 ---------- x4
>
> 104 ---- 145.455 ---- 446.493 ---- 1381.006 ---- 2472.230
> 104 ---- 142.857 ---- 415.004 ---- 1556.626 ---- 2553.037
> 104 ---- 145.455 ---- 540.619 ---- 1778.841 ---- 2539.434
> 105 ---- 150.943 ---- 405.916 ---- 1307.187 ---- 2483.152
> 104 ---- 142.857 ---- 420.071 ---- 1764.712 ---- 2553.209
> 105 ---- 142.857 ---- 445.416 ---- 1519.577 ---- 2498.646
> 103 ---- 148.148 ---- 316.140 ---- 1728.223 ---- 2544.723
> 102 ---- 148.148 ---- 372.026 ---- 1529.687 ---- 2473.594
> 106 ---- 235.294 ---- 361.520 ---- 1493.840 ---- 2602.597
> 106 ---- 228.571 ---- 427.001 ---- 1778.426 ---- 2571.960
> 106 ---- 235.294 ---- 434.787 ---- 1505.175 ---- 2753.895
>
> I now this can be accomplished with function "polyfit", but
> I didn't understand from help, how should I do it. Should I
> make matrice from those x vectors and present that matrice
> as x in "polyfit" function?
>
> Thanks for help

No. Polyfit cannot do this. You can either
use backslash, or download my polyfitn
from the file exchange.

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?
objectId=10065&objectType=FILE

John




Subject: function polyfit

From: beda meda

Date: 15 May, 2008 09:20:19

Message: 7 of 7

richardstartz@comcast.net wrote in message
<q3lm24d6102eq72sfa2tvb226bosoo2tha@4ax.com>...
> On Wed, 14 May 2008 21:05:05 +0000 (UTC), "beda meda"
> <b.meda@centrum.cz> wrote:
>
> >NZTideMan <mulgor@gmail.com> wrote in message
>
><08bcf48a-93cf-4651-a763-b00d212b1f2d@c19g2000prf.googlegroups.com>...
> >> On May 15, 7:48=A0am, "beda meda" <b.m...@centrum.cz>
wrote:
> >> > Hi,
> >> > I have one vector of variable y and four vectors of
x1, x2,
> >> > x3 and x4. And I need to aproximate y by least squares
> >> > method from all vectors x. Example:
> >> >
> >> > y --------- x1 --------- x2 --------- x3 ---------- x4
> >> >
> >> > 104 ---- 145.455 ---- 446.493 ---- 1381.006 ---- 2472.230
> >> > 104 ---- 142.857 ---- 415.004 ---- 1556.626 ---- 2553.037
> >> > 104 ---- 145.455 ---- 540.619 ---- 1778.841 ---- 2539.434
> >> > 105 ---- 150.943 ---- 405.916 ---- 1307.187 ---- 2483.152
> >> > 104 ---- 142.857 ---- 420.071 ---- 1764.712 ---- 2553.209
> >> > 105 ---- 142.857 ---- 445.416 ---- 1519.577 ---- 2498.646
> >> > 103 ---- 148.148 ---- 316.140 ---- 1728.223 ---- 2544.723
> >> > 102 ---- 148.148 ---- 372.026 ---- 1529.687 ---- 2473.594
> >> > 106 ---- 235.294 ---- 361.520 ---- 1493.840 ---- 2602.597
> >> > 106 ---- 228.571 ---- 427.001 ---- 1778.426 ---- 2571.960
> >> > 106 ---- 235.294 ---- 434.787 ---- 1505.175 ---- 2753.895
> >> >
> >> > I now this can be accomplished with function
"polyfit", but
> >> > I didn't understand from help, how should I do it.
Should I
> >> > make matrice from those x vectors and present that
matrice
> >> > as x in "polyfit" function?
> >> >
> >> > Thanks for help
> >>
> >> Polyfit's the wrong one for this.
> >> help mldivide
> >> Take special notice of the 2nd paragraph which talks about
> >least
> >> squares
> >> coef=3D[x1 x2 x3 x4]\y
> >
> >I think this is what I need, thanks!
> >---------------------------
> >
> >to Dick:
> >You meant I should divide matrice x by y and then use
> >polyfit? Or if not, what did you mean?
> >
> >But thank you too!
>
> Basically, I was saying the same thing NZTide said. The
coefficients
> are
>
> coef=[x1 x2 x3 x4]\y;
>
> The approximated value is
>
> [x1 x2 x3 x4]*coef;

OK, thanks.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
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 Disclaimer prior to use.
Related Topics