Got Questions? Get Answers.
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:
passing a polynomial to a function

Subject: passing a polynomial to a function

From: Snow White

Date: 11 Oct, 2010 19:13:04

Message: 1 of 7

Hello,

is there a way of passing a polynomial to a function. i have a polynomial as follows:

p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];

which i pass into another function as:

[m]=newton_method(p,m0);

but when it is passed to the function it acquires some random value which is not the value of the polynomial that has been passed...

is there a way of doing that?

bye

Subject: passing a polynomial to a function

From: dpb

Date: 11 Oct, 2010 19:48:13

Message: 2 of 7

Snow White wrote:
> Hello,
>
> is there a way of passing a polynomial to a function. i have a
> polynomial as follows:
>
> p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];
...

What are the dimensions of A, B, ...?

If they're scalars, then p is a vector.

If they're (column) vectors, then p is an array of length(A) rows by 5.
  If they're (row) vectors, the p is a row vector of length(A)*5.
I guess you can extrapolate to matrices... :)

Short story is, evaluate

  p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2]

at the command line and all should be revealed (note no trailing ";")

--

Subject: passing a polynomial to a function

From: Snow White

Date: 12 Oct, 2010 11:52:04

Message: 3 of 7

A B C D are all column vectors.

dpb <none@non.net> wrote in message <i8vptr$kvn$1@news.eternal-september.org>...
> Snow White wrote:
> > Hello,
> >
> > is there a way of passing a polynomial to a function. i have a
> > polynomial as follows:
> >
> > p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];
> ...
>
> What are the dimensions of A, B, ...?
>
> If they're scalars, then p is a vector.
>
> If they're (column) vectors, then p is an array of length(A) rows by 5.
> If they're (row) vectors, the p is a row vector of length(A)*5.
> I guess you can extrapolate to matrices... :)
>
> Short story is, evaluate
>
> p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2]
>
> at the command line and all should be revealed (note no trailing ";")
>
> --

Subject: passing a polynomial to a function

From: dpb

Date: 12 Oct, 2010 12:28:10

Message: 4 of 7

Snow White wrote:
...[top posting repaired...don't do that; hard makes conversation follow]...

> dpb <none@non.net> wrote in message
> <i8vptr$kvn$1@news.eternal-september.org>...
>> Snow White wrote:
>> > Hello,
>> > > is there a way of passing a polynomial to a function. i have a >
>> polynomial as follows:
>> > > p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];
>> ...
>>
>> What are the dimensions of A, B, ...?
>>
>> If they're scalars, then p is a vector.
>>
>> If they're (column) vectors, then p is an array of length(A) rows by
>> 5. If they're (row) vectors, the p is a row vector of length(A)*5.
>> I guess you can extrapolate to matrices... :)
...

> A B C D are all column vectors.

So, p is a 2D array.

What's the problem?

Are you searching for

doc polyvalm % , perhaps?

--

Subject: passing a polynomial to a function

From: Snow White

Date: 12 Oct, 2010 13:47:03

Message: 5 of 7

dpb <none@non.net> wrote in message <i91kgm$kc5$1@news.eternal-september.org>...
> Snow White wrote:
> ...[top posting repaired...don't do that; hard makes conversation follow]...
>
> > dpb <none@non.net> wrote in message
> > <i8vptr$kvn$1@news.eternal-september.org>...
> >> Snow White wrote:
> >> > Hello,
> >> > > is there a way of passing a polynomial to a function. i have a >
> >> polynomial as follows:
> >> > > p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];
> >> ...
> >>
> >> What are the dimensions of A, B, ...?
> >>
> >> If they're scalars, then p is a vector.
> >>
> >> If they're (column) vectors, then p is an array of length(A) rows by
> >> 5. If they're (row) vectors, the p is a row vector of length(A)*5.
> >> I guess you can extrapolate to matrices... :)
> ...
>
> > A B C D are all column vectors.
>
> So, p is a 2D array.
>
> What's the problem?
>
> Are you searching for
>
> doc polyvalm % , perhaps?
>
> --
p is n x5

when i pass this to a function the values that i get are garbbage!

Subject: passing a polynomial to a function

From: dpb

Date: 12 Oct, 2010 14:26:12

Message: 6 of 7

Snow White wrote:
> dpb <none@non.net> wrote in message
> <i91kgm$kc5$1@news.eternal-september.org>...
>> Snow White wrote:
>> ...[top posting repaired...don't do that; hard makes conversation
>> follow]...
>>
>> > dpb <none@non.net> wrote in message >
>> <i8vptr$kvn$1@news.eternal-september.org>...
>> >> Snow White wrote:
>> >> > Hello,
>> >> > > is there a way of passing a polynomial to a function. i have a
>> > >> polynomial as follows:
>> >> > > p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];
>> >> ...
>> >>
>> >> What are the dimensions of A, B, ...?
>> >>
>> >> If they're scalars, then p is a vector.
>> >>
>> >> If they're (column) vectors, then p is an array of length(A) rows
>> by >> 5. If they're (row) vectors, the p is a row vector of
>> length(A)*5.
>> >> I guess you can extrapolate to matrices... :)
>> ...
>>
>> > A B C D are all column vectors.
>>
>> So, p is a 2D array.
>>
>> What's the problem?
>>
>> Are you searching for
>>
>> doc polyvalm % , perhaps?
>>
>> --
> p is n x5
>
> when i pass this to a function the values that i get are garbbage!

Can't see what you don't show...

--

Subject: passing a polynomial to a function

From: Loren Shure

Date: 12 Oct, 2010 19:21:57

Message: 7 of 7


"dpb" <none@non.net> wrote in message
news:i91rds$qu3$2@news.eternal-september.org...
> Snow White wrote:
>> dpb <none@non.net> wrote in message
>> <i91kgm$kc5$1@news.eternal-september.org>...
>>> Snow White wrote:
>>> ...[top posting repaired...don't do that; hard makes conversation
>>> follow]...
>>>
>>> > dpb <none@non.net> wrote in message >
>>> <i8vptr$kvn$1@news.eternal-september.org>...
>>> >> Snow White wrote:
>>> >> > Hello,
>>> >> > > is there a way of passing a polynomial to a function. i have a
>>> > >> polynomial as follows:
>>> >> > > p= [A.^2 (2.*A.*C-1) ((2.*A.*B)+(C.^2)+D) 2.*B.*C B.^2];
>>> >> ...
>>> >>
>>> >> What are the dimensions of A, B, ...?
>>> >>
>>> >> If they're scalars, then p is a vector.
>>> >>
>>> >> If they're (column) vectors, then p is an array of length(A) rows
>>> by >> 5. If they're (row) vectors, the p is a row vector of
>>> length(A)*5.
>>> >> I guess you can extrapolate to matrices... :)
>>> ...
>>>
>>> > A B C D are all column vectors.
>>>
>>> So, p is a 2D array.
>>>
>>> What's the problem?
>>>
>>> Are you searching for
>>>
>>> doc polyvalm % , perhaps?
>>>
>>> --
>> p is n x5
>>
>> when i pass this to a function the values that i get are garbbage!
>
From doc for polyvalm:

Y = polyvalm(p,X) evaluates a polynomial in a matrix sense. This is the same
as substituting matrix X in the polynomial p.

Polynomial p is a vector whose elements are the coefficients of a polynomial
in descending powers, and X must be a square matrix.

Your p is a matrix, not a vector.
--
Loren
http://blogs.mathworks.com/loren/
http://matlabwiki.mathworks.com/MATLAB_FAQ

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