Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

My teacher suggests using the RandomInteger command along with the Factor command, but I cannot figure out the syntax. A, b, and c need to be non zero integers between -10 and 10.

share|improve this question
4  
Look at the documentation. You haven't explained what is your problem. Everyone has some problems with the syntax. –  Artes Feb 11 at 20:53
    
I looked at the documentation and understand how the RandomInteger command works, I'm just not sure where or how to apply it to the a, b, and c in the quadratic. –  Kristie Feb 11 at 21:02
1  
Don't accept an answer so quickly. I was working on one of my own. –  rcollyer Feb 11 at 21:12
1  
I didn't actually mean to, new to this! –  Kristie Feb 11 at 21:13
add comment

4 Answers

rand := RandomInteger[{-10, 9}] /. (0 -> 10)
eq := rand x^2 + rand x + rand
Array[eq &, {25}]

{5 - 3 x - 6 x^2, -9 - 6 x + 5 x^2, -2 - 6 x + 9 x^2, 7 - 6 x + 9 x^2, 2 + 8 x + 8 x^2, 3 - x + 5 x^2, -10 + 4 x - 5 x^2, -4 + 6 x + 10 x^2, 2 - 5 x - 5 x^2, -7 - 2 x - 8 x^2, -7 - 4 x - 6 x^2, -1 - 2 x + 7 x^2, 8 - 2 x + x^2, 5 + 2 x + 6 x^2, -8 + 3 x + 9 x^2, 2 - 2 x + 10 x^2, -9 + 2 x - 10 x^2, 7 + 9 x + 5 x^2, 4 - 5 x + 6 x^2, 8 - 6 x - 9 x^2, -1 + 7 x - 10 x^2, 4 - 6 x - 4 x^2, 5 - 3 x - 3 x^2, 2 + 9 x - 9 x^2, 1 - 3 x + 5 x^2}

Edit:

(1) If you want the order to be exactly a x^2 + b x + c, instead of c + b x + a x^2, you can do PolynomialForm[Array[eq &, {25}], TraditionalOrder -> True]

(2) By the way, one cannot write .../.0->10 . Otherwise Mathematica parse it as ... divided by 0.0

share|improve this answer
    
I would make one small change. I would use Array[eq&, {25}] instead. For the small list size, it won't matter, but for larger lists sizes, why build a list you are never going to use? –  rcollyer Feb 11 at 21:11
    
Thanks! That's true. –  Yi Wang Feb 11 at 21:16
add comment

Here's a slightly different method. Except for the fact that you want non-zero integers, RandomInteger would be perfect for this, e.g.

len = 5;
RandomInteger[{-10, 10}, {len, 3}]
(* 
 {{-3, -2, 10}, {2, -3, -8}, {5, 3, -2}, {9, 3, -2}, {-9, 3, -6}}
*)

which gives your list of triples directly. Now, you could alter the range and make substitutions like Yi Wang, but I think RandomChoice may be better, e.g.

RandomChoice[Range[10]~Join~(-Range[10]), {len, 3}]
(*
 {{3, -3, -7}, {8, -1, -5}, {-2, -6, 5}, {-2, -4, 1}, {-8, 6, -8}}
*)

Then, constructing your polynomial is easy

#1 x^2 + #2 x + #3& @@@ RandomChoice[Range[10]~Join~(-Range[10]), {len, 3}]
(*
 {-6 - 7 x + 7 x^2, -6 - 4 x - 4 x^2, -2 - 5 x + 3 x^2, 
  6 + x + 7 x^2, 4 + 10 x + 10 x^2}
*)

Obviously, increasing len to 25 for your application.

share|improve this answer
add comment

Here is a rough way to achieve this:

RandomPolynomial[max_Integer, var_Symbol] :=  Module[{pol, lis}, 
 lis = Table[RandomChoice@Join[Range[-10, -1], Range[10]] var^deg, {deg, max,0, -1}]; pol = Tr@lis]

Now let's create 25 of these:

Table[RandomPolynomial[2, x], {25}]

Mathematica graphics

share|improve this answer
    
RandomInteger works, except for the requirement that the coefficients are non-zero. –  rcollyer Feb 11 at 21:20
    
@rcollyer, Thanks, didn't catch that. –  RunnyKine Feb 11 at 21:21
add comment

This goofy way will let you specify how many to generate, the maximum power of x, and the +/- range of coefficients to use (excluding zero):

Plus @@@ Table[(RandomInteger[{-#3, #3 - 1}] /. (0 -> #3)) x^s, {#1}, {s, 0, #2}] &[5, 2, 10]
(*  {-4 + 10 x - x^2, -10 - 5 x + 6 x^2,  5 - 6 x + 10 x^2, -8 - 9 x - 5 x^2, -6 - 9 x - 5 x^2}  *)

Same result, more compact realization:

(RandomInteger[2 #3 - 1, {#, #2 + 1}] - #3 /. (0 -> #3)).x^Range[0, #2] &[5, 2, 10]

You can use //TraditionalForm on the output if you want it in decreasing exponent order.

Credit to Yi Wang for zero elimination idea.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.