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 roots

Subject: Polynomial roots

From: Mark

Date: 29 Apr, 2010 21:15:22

Message: 1 of 6

I'm trying to find the roots of 100 random polynomials of degree 5 and I need help with finding the roots. I know that I can gernerate 100 polynomials by using
                                          >> x=rand([100 6])
I know that I can't do
                                          >> roots(x)
because the the input must be a vector. Is there anyway to to find all the roots of 100 random polynomials without generating each polynomial one by one.

Subject: Polynomial roots

From: Walter Roberson

Date: 29 Apr, 2010 21:29:11

Message: 2 of 6

Mark wrote:
> I'm trying to find the roots of 100 random polynomials of degree 5 and I
> need help with finding the roots. I know that I can gernerate 100
> polynomials by using
> >> x=rand([100 6])
> I know that I can't do >> roots(x)
> because the the input must be a vector. Is there anyway to to find all
> the roots of 100 random polynomials without generating each polynomial
> one by one.

Not for degree 5. For degree 4, there would be exact solutions you could
plug the coefficients into, but for degree 5 unless you are lucky enough
to be able to factorize, you need to use something like a binary search
for sign changes over a hypothesized interval.

I'm not saying that it would not be possible to build a routine that did
this kind of search in parallel, but it isn't the way the built-in
routines are set up.

Subject: Polynomial roots

From: Steven Lord

Date: 29 Apr, 2010 21:43:18

Message: 3 of 6


"Mark " <bobbb909@yahoo.com> wrote in message
news:hrcsta$g22$1@fred.mathworks.com...
> I'm trying to find the roots of 100 random polynomials of degree 5 and I
> need help with finding the roots. I know that I can gernerate 100
> polynomials by using
> >> x=rand([100 6])
> I know that I can't do >> roots(x)
> because the the input must be a vector. Is there anyway to to find all the
> roots of 100 random polynomials without generating each polynomial one by
> one.

Loop over the rows of x and call ROOTS on each row, storing the roots back
into rows or columns of another matrix or into a cell array (depending on
how you need them.)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Polynomial roots

From: us

Date: 29 Apr, 2010 21:46:04

Message: 4 of 6

"Mark " <bobbb909@yahoo.com> wrote in message <hrcsta$g22$1@fred.mathworks.com>...
> I'm trying to find the roots of 100 random polynomials of degree 5 and I need help with finding the roots. I know that I can gernerate 100 polynomials by using
> >> x=rand([100 6])
> I know that I can't do
> >> roots(x)
> because the the input must be a vector. Is there anyway to to find all the roots of 100 random polynomials without generating each polynomial one by one.

a hint:

     help num2cell;
     help cellfun;

us

Subject: Polynomial roots

From: Mark

Date: 1 May, 2010 22:10:08

Message: 5 of 6

"Steven Lord" <slord@mathworks.com> wrote in message <hrcuhl$1r6$1@fred.mathworks.com>...
>
> "Mark " <bobbb909@yahoo.com> wrote in message
> news:hrcsta$g22$1@fred.mathworks.com...
> > I'm trying to find the roots of 100 random polynomials of degree 5 and I
> > need help with finding the roots. I know that I can gernerate 100
> > polynomials by using
> > >> x=rand([100 6])
> > I know that I can't do >> roots(x)
> > because the the input must be a vector. Is there anyway to to find all the
> > roots of 100 random polynomials without generating each polynomial one by
> > one.
>
> Loop over the rows of x and call ROOTS on each row, storing the roots back
> into rows or columns of another matrix or into a cell array (depending on
> how you need them.)
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
How would I wrtie the for loop? Here is what I got so far

N=100;
x=zeros(100, 6); % cretes an empty 100 x 6 matrix

for k=1:N
    x(k)=roots(rand([1 6]));
end

x
I know that this won't work so how can I get it to work.

Subject: Polynomial roots

From: Roger Stafford

Date: 2 May, 2010 02:55:23

Message: 6 of 6

"Mark " <bobbb909@yahoo.com> wrote in message <hri8s0$gjm$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <hrcuhl$1r6$1@fred.mathworks.com>...
> >
> > "Mark " <bobbb909@yahoo.com> wrote in message
> > news:hrcsta$g22$1@fred.mathworks.com...
> > > I'm trying to find the roots of 100 random polynomials of degree 5 and I
> > > need help with finding the roots. I know that I can gernerate 100
> > > polynomials by using
> > > >> x=rand([100 6])
> > > I know that I can't do >> roots(x)
> > > because the the input must be a vector. Is there anyway to to find all the
> > > roots of 100 random polynomials without generating each polynomial one by
> > > one.
> >
> > Loop over the rows of x and call ROOTS on each row, storing the roots back
> > into rows or columns of another matrix or into a cell array (depending on
> > how you need them.)
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> >
> How would I wrtie the for loop? Here is what I got so far
>
> N=100;
> x=zeros(100, 6); % cretes an empty 100 x 6 matrix
>
> for k=1:N
> x(k)=roots(rand([1 6]));
> end
>
> x
> I know that this won't work so how can I get it to work.
-----------
  You're almost there. Just add a colon. And use 100 x 5 size.

N=100;
x=zeros(100, 5); % creates an empty 100 x 5 matrix
for k=1:N
   x(k,:) = roots(randn([1 6]));
end

Roger Stafford

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