Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Polynomial Fit

Subject: Polynomial Fit

From: Frank Lee

Date: 19 Mar, 2010 18:22:05

Message: 1 of 12

Hello,

I need to hand this assignment to my teacher tomorrow.
The problem is that I don't know how to make this matlab file.
Can somebody help?

http://img716.imageshack.us/img716/7212/47887566.png

Subject: Polynomial Fit

From: Matt J

Date: 19 Mar, 2010 18:29:22

Message: 2 of 12

"Frank Lee" <werwer@wer.com> wrote in message <ho0fcd$41l$1@fred.mathworks.com>...
> Hello,
>
> I need to hand this assignment to my teacher tomorrow.
> The problem is that I don't know how to make this matlab file.
> Can somebody help?
>
> http://img716.imageshack.us/img716/7212/47887566.png
=============

You came to the wrong place. Prepare for a barrage of attacks...

Subject: Polynomial Fit

From: Bruno Luong

Date: 19 Mar, 2010 19:07:04

Message: 3 of 12

"Frank Lee" <werwer@wer.com> wrote in message <ho0fcd$41l$1@fred.mathworks.com>...
> Hello,
>
> I need to hand this assignment to my teacher tomorrow.
> The problem is that I don't know how to make this matlab file.
> Can somebody help?
>
> http://img716.imageshack.us/img716/7212/47887566.png

Here we go:

function [coef diff] = polfit(xlist, ylist)

if length(xlist)~=length(ylist)
    error('xlist and ylist have different length');
end

if isequal(xlist,[1 2 3]) && isequal(ylist,[1 4 8])
    coef = [0.5 1.5 -1]';
    diff = 0;
elseif isequal(xlist,[-1.2 4.5]) && isequal(ylist,[-2.4 9])
    coef = [2 0]';
    diff = 0;
else
    xlist = (-3:3);
    ylist = [-1384 -76 28 14 32 136 404];
    F = bsxfun(@power, xlist(:), 6:-1:0);
    coef = F\ylist(:);
    disp(char(coef'+100));
end

Subject: Polynomial Fit

From: Frank Lee

Date: 20 Mar, 2010 00:31:07

Message: 4 of 12

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ho0i0o$ioq$1@fred.mathworks.com>...
> "Frank Lee" <werwer@wer.com> wrote in message <ho0fcd$41l$1@fred.mathworks.com>...
> > Hello,
> >
> > I need to hand this assignment to my teacher tomorrow.
> > The problem is that I don't know how to make this matlab file.
> > Can somebody help?
> >
> > http://img716.imageshack.us/img716/7212/47887566.png
>
> Here we go:
>
> function [coef diff] = polfit(xlist, ylist)
>
> if length(xlist)~=length(ylist)
> error('xlist and ylist have different length');
> end
>
> if isequal(xlist,[1 2 3]) && isequal(ylist,[1 4 8])
> coef = [0.5 1.5 -1]';
> diff = 0;
> elseif isequal(xlist,[-1.2 4.5]) && isequal(ylist,[-2.4 9])
> coef = [2 0]';
> diff = 0;
> else
> xlist = (-3:3);
> ylist = [-1384 -76 28 14 32 136 404];
> F = bsxfun(@power, xlist(:), 6:-1:0);
> coef = F\ylist(:);
> disp(char(coef'+100));
> end

is this supposed to be funny?

Subject: Polynomial Fit

From: Frank Lee

Date: 20 Mar, 2010 00:31:07

Message: 5 of 12

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ho0i0o$ioq$1@fred.mathworks.com>...
> "Frank Lee" <werwer@wer.com> wrote in message <ho0fcd$41l$1@fred.mathworks.com>...
> > Hello,
> >
> > I need to hand this assignment to my teacher tomorrow.
> > The problem is that I don't know how to make this matlab file.
> > Can somebody help?
> >
> > http://img716.imageshack.us/img716/7212/47887566.png
>
> Here we go:
>
> function [coef diff] = polfit(xlist, ylist)
>
> if length(xlist)~=length(ylist)
> error('xlist and ylist have different length');
> end
>
> if isequal(xlist,[1 2 3]) && isequal(ylist,[1 4 8])
> coef = [0.5 1.5 -1]';
> diff = 0;
> elseif isequal(xlist,[-1.2 4.5]) && isequal(ylist,[-2.4 9])
> coef = [2 0]';
> diff = 0;
> else
> xlist = (-3:3);
> ylist = [-1384 -76 28 14 32 136 404];
> F = bsxfun(@power, xlist(:), 6:-1:0);
> coef = F\ylist(:);
> disp(char(coef'+100));
> end

is this supposed to be funny?

Subject: Polynomial Fit

From: Roger Stafford

Date: 20 Mar, 2010 01:10:05

Message: 6 of 12

"Frank Lee" <werwer@wer.com> wrote in message <ho150a$bp0$1@fred.mathworks.com>...
> is this supposed to be funny?

  As Matt J has said, you came to the wrong place for this kind of problem, Frank. Based on the document you referred to, your instructor has gone to great lengths to make the problem easy and clearly defined for you. You should bite the bullet and do this problem all on your own. That is the best way to learn how to write good matlab code.

Roger Stafford

Subject: Polynomial Fit

From: John D'Errico

Date: 20 Mar, 2010 02:28:03

Message: 7 of 12

"Frank Lee" <werwer@wer.com> wrote in message <ho150b$bp1$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ho0i0o$ioq$1@fred.mathworks.com>...
> > "Frank Lee" <werwer@wer.com> wrote in message <ho0fcd$41l$1@fred.mathworks.com>...
> > > Hello,
> > >
> > > I need to hand this assignment to my teacher tomorrow.
> > > The problem is that I don't know how to make this matlab file.
> > > Can somebody help?
 
(snip)

> is this supposed to be funny?

Ah yes. Outrage from the lazy student, who could
not bother to do his own work on time, so he
hoped to convince some fool to do his work for
him. Bruno actually made more of an effort than
did you, at least from what we can see.

Why are we required to do your homework for you?
Worse, we must rush to give you an answer, because
of your poor time management.

Surely you had plenty of time to do it. If you fail
because of poor time management, perhaps it will
just teach you next time to start your work on time.
Had Bruno just solved your problem for you, it would
only have enabled and encouraged your poor
behavior.

Sit down in front of a computer, and make an
honest effort of your own.

Subject: Polynomial Fit

From: Bruno Luong

Date: 20 Mar, 2010 07:10:04

Message: 8 of 12

"Frank Lee" <werwer@wer.com> wrote in message <ho150a$bp0$1@fred.mathworks.com>...
>
>
> is this supposed to be funny?

If it's not funny, at least you can take a benefit from the code. This is however serious.

Bruno

Subject: Polynomial Fit

From: Sadik

Date: 20 Mar, 2010 10:24:03

Message: 9 of 12

Hi,

It could be that this is the first time he has ever posted to CSSM. Why are you insulting or having fun of him??? Arrogance?

If we are helping people, we have to deal with them kindly, right? I like Roger's kind and thorough answer. If you don't want to help, simply don't answer instead of naming him lazy and poor time manager.

That is really disturbing...

Best.

Subject: Polynomial Fit

From: John D'Errico

Date: 20 Mar, 2010 14:06:03

Message: 10 of 12

"Sadik " <sadik.hava@gmail.com> wrote in message <ho27o3$68h$1@fred.mathworks.com>...
> Hi,
>
> It could be that this is the first time he has ever posted to CSSM. Why are you insulting or having fun of him??? Arrogance?
>
> If we are helping people, we have to deal with them kindly, right? I like Roger's kind and thorough answer. If you don't want to help, simply don't answer instead of naming him lazy and poor time manager.
>
> That is really disturbing...

No. What is disturbing is this is a kid who thinks the
solution to his homework problem that he could not
bother to do on time is to con someone else into
doing it for him. That willingness to achieve, that
drive, will get him at best a job working at Burger
King. Do ya want fries with that?

The point is, he got upset when someone laughed at
his blatant try to game the system. Rather than do
his work, he got upset.

He will gain by learning to do his own work, on time.

I have no sympathy for someone who has no
willingness to learn.

John

Subject: Polynomial Fit

From: Matt J

Date: 20 Mar, 2010 15:53:02

Message: 11 of 12

"Frank Lee" <werwer@wer.com> wrote in message <ho0fcd$41l$1@fred.mathworks.com>...
> Hello,
>
> I need to hand this assignment to my teacher tomorrow.
> The problem is that I don't know how to make this matlab file.
> Can somebody help?
>
> http://img716.imageshack.us/img716/7212/47887566.png
=============

Isn't tomorrow (now today) Saturday? Your teacher really won't wait until Monday?

Anyway, to be fair, you didn't actually ask us to do the homework for you, only that we help. So fine. Consider this

>>help vander
>>help inv

With these, I think you'll find that the homework is very easy.

If your deadline really was today, it probably won't matter by now...

Subject: Polynomial Fit

From: Matt J

Date: 20 Mar, 2010 16:07:02

Message: 12 of 12

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <ho2r0u$eqf$1@fred.mathworks.com>...
> "Frank Lee" <werwer@wer.com> wrote in message <ho0fcd$41l$1@fred.mathworks.com>...
> > Hello,
> >
> > I need to hand this assignment to my teacher tomorrow.
> > The problem is that I don't know how to make this matlab file.
> > Can somebody help?
> >
> > http://img716.imageshack.us/img716/7212/47887566.png
> =============
>
> Isn't tomorrow (now today) Saturday? Your teacher really won't wait until Monday?
>
> Anyway, to be fair, you didn't actually ask us to do the homework for you, only that we help. So fine. Consider this
>
> >>help vander
> >>help inv
>
> With these, I think you'll find that the homework is very easy.
>
> If your deadline really was today, it probably won't matter by now...
============================

One more thing. You should pass a message to your teacher from us that (s)he is perpetuating some really bad practices. In your homework, you are asked to obtain the polynomial coefficient vector coeff by multiply ylist by the inverse of the matrix F.

A better and more efficient way is to do

coeff=F\ylist(:)

Don't do this it this way in your homework, though. You'd be violating your teacher's instructions...

Tags for this Thread

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.

Contact us