Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: need some help for this linear regression that was assigned for homework
Replies: 2   Last Post: Apr 13, 2012 11:20 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Claudio

Posts: 11
Registered: 11/18/11
Re: need some help for this linear regression that was assigned for homework
Posted: Apr 13, 2012 11:20 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Sargondjani" wrote in message <jm5rgi$2fl$1@newscl01ah.mathworks.com>...
> "omar rodriguez" <omrodez@yahoo.com> wrote in message <jm5i69$1de$1@newscl01ah.mathworks.com>...
> > Use the following data point generated using random function and write a matlab code to fit a 2nd order polynomia. Please upload the MATLAB code for the following data-sets.
> >
> > x=[0 .1 .2 .3 .4 .5 .6 .7 .8 .9];
> > y=[70. 74. 78. 80. 81. 83. 84. 85. 87. 87.];
> >
> > 1) Use polyfit command.
> > 2) Without using the polyfit,.
> >
> > x=0:.1:0.9;
> > y=[70,74,78,80,81,83,84,85,87,87];
> > n=1;
> > p=polyfit(x,y,n);
> > f=a0+a1*x;
> > a0=p(2)
> > a1=p(1)
> > plot(x,f,x,y,'o')
> >

>
> you should use n=2 for second order polynomial. and then f=a0+a1*x+a2*x.^2
> If you want to do it yourself:
>
> x=x'; %x should be column vector
>
> X=[x.^0,x.^1,x.^2]; %of course x.^0 is a vector of 1's
>
> y=y'; %y should be a column vector
>
> a=regress(y,X); % or you could do a=X\y but i think regress is better



You should also assign a0 and a1 BEFORE usinge them:
a0=p(3);
a1=p(2);
a2=p(1);
f=a0+a1*x+a2*x.^2;





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.