Results 1 to 3 of 3

Math Help - Matlab roots help

  1. #1
    Newbie
    Joined
    Mar 2010
    Posts
    2

    Matlab roots help

    I need help in generating 100 different polynomials of a certain degree and then finding the total number real roots. I know that I can generate a random polynomial of say degree 5 by typing

    x=roots(rand([1 6]))
    I also figured out the total number of real numbers by typing
    size(x(imag(x)==0))
    Can someone help me in writing a for loop for this?
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by YankeesFan View Post
    I need help in generating 100 different polynomials of a certain degree and then finding the total number real roots. I know that I can generate a random polynomial of say degree 5 by typing

    x=roots(rand([1 6]))
    I also figured out the total number of real numbers by typing
    size(x(imag(x)==0))
    Can someone help me in writing a for loop for this?
    x=roots(rand([1 6]))

    will not generate the polynomials and roots you want as all the coefficients will be positive and so before you start you have no positive roots.

    Try:

    x=roots(rand([1 6]-0.5))

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by YankeesFan View Post
    I need help in generating 100 different polynomials of a certain degree and then finding the total number real roots. I know that I can generate a random polynomial of say degree 5 by typing

    x=roots(rand([1 6]))
    I also figured out the total number of real numbers by typing
    size(x(imag(x)==0))
    Can someone help me in writing a for loop for this?
    Basic for loop structure is:

    Code:
    rv=zeros(1,100);
    for idx=1:100
       
       %code to do what you want
    
       rv(idx)=...  ; % assign the idx-th element of the
                      % results vector to result for current
                      % loop trip
    end
    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Finding roots of a polynomial of 5th order in Matlab.
    Posted in the Math Software Forum
    Replies: 9
    Last Post: February 7th 2011, 12:54 AM
  2. Matlab
    Posted in the Math Software Forum
    Replies: 1
    Last Post: April 16th 2010, 04:11 AM
  3. Roots & Imaginary Roots
    Posted in the Math Topics Forum
    Replies: 4
    Last Post: October 4th 2009, 09:24 AM
  4. Given 2 imaginary roots find other 2 roots
    Posted in the Pre-Calculus Forum
    Replies: 1
    Last Post: January 26th 2008, 09:24 PM
  5. Matlab
    Posted in the Math Software Forum
    Replies: 4
    Last Post: November 15th 2007, 08:23 AM

Search Tags


/mathhelpforum @mathhelpforum