0

I'm trying to generate a multiple choice question set for rational numbers for the following operations: addition, subtraction, multiplication and division.

Something like

01) the value of 2/3 + 5/4 is: a) b) c) d) e)

02) the value of 2/3 * 5/8 is: a) b) c) d) e)

and so on for about 25 questions. How do I do this using Mathematica?

EDIT

  1. I get an error when I try to run yoda's code and couldn't figure out why. Here's the error message:

  2. Here is a mockup showing the final output that I'd like:

  3. The number generation is good, but would be better if they were in the interval -100 < x < 100 at random.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
zeroo
  • 11
  • 1
  • 1
    I'm not entirely sure what you're asking. Do you want to randomly generate a problem set dealing the mathematics of fractions? – rcollyer Jan 16 '12 at 03:24

2 Answers2

3

My interpretation is the same as that of rcollyer's – you want to randomly generate 25 pairs of rational numbers and with the 4 choices being the result of {+,-,*,/} on each pair, but in a shuffled order. The question is then a single randomly chosen operation on the corresponding pair of fractions.

In order to do that, I strongly suggest reading the answer to Sasha's question on generating uniformly distributed rational numbers with an upper bound on the denominator. Specifically, the function RandomFarey, which is Sasha's implementation of btilly's answer. I suggest this instead of the more intuitive Rationalize[RandomReal[...]] approach, because if you're setting a homework for fractions, it's probably for an elementary/middle school class, and you might not want any arbitrary rational number that the obvious approach might throw up (e.g., {273/391, 193/239}, which probably might be a bit too much, depending on the level).

Now that we have a generating function for the rational numbers, all that needs to be done is generating them up, creating the answer choices, shuffling, and creating a random set of questions and laying them out neatly. Here's one approach of doing that.

makeHomework[n_Integer, denominator_Integer] := 
 Module[{rationalPairs = RandomFarey[denominator, 2 n]~Partition~2, 
   operators = {Plus, Subtract, Times, Divide}, 
   randomOp := RandomChoice[{"+", "-", "\[Times]", "\[Divide]"}], 
   choiceList, questionList},

  choiceList = Outer[Apply, operators, rationalPairs, 1];
  questionList = #1 <> randomOp <> #2 <> "=" & @@@ 
    Map[ToString[# // TraditionalForm] &, rationalPairs, {2}];

  Grid[Transpose@{questionList, 
     Row@MapThread[Labeled, {#, {"(a)", "(b)", "(c)", "(d)"}}] & /@ 
      Transpose@choiceList},
   Spacings -> {0, 1}]
  ]

For example, evaluating makeHomework[5, 10] gives:

enter image description here

This probably takes you 90% of the way there. I'm really in a rush, so there are a few things I have not done, but I hope that you or someone else can address it. They're mostly trivial.

  1. I don't account for integers. These will mess up the layout (that one will be a little off the line), if the generator were to throw one up.
  2. I forgot the serial number
  3. The label sizes should be smaller (or conversely, the numbers should be bigger)
  4. Other frills and prettifications
Community
  • 1
  • 1
abcd
  • 41,765
  • 7
  • 81
  • 98
  • First of all thank you very much for responding sorry for my English, maybe no means all, use Google translator, not yet very well how this page works and how to operate Comment – zeroo Jan 16 '12 at 16:59
  • see my question above edition .. sorry I'm not even here management – zeroo Jan 16 '12 at 18:25
  • @zeroo I've formatted your question & edit. The code for `RandomFarey` is in Sasha's question that I linked to in my answer, and you'll also need to evaluate `cfPairs` and `cfGCD` to use `RandomFarey`. Once you do that, it should evaluate for you. – abcd Jan 16 '12 at 19:14
  • ********there put "Random Farey" and cfGCD cfPairs but your code, but I get a lot of errors when you run, what am I doing wrong? , plese look my second edition... – zeroo Jan 17 '12 at 01:49
  • ***edit 2 put image will not let me do anything ![](http://imageshack.us/photo/my-images/651/edit2vr.jpg) – zeroo Jan 17 '12 at 02:36
  • @zeroo What version of Mathematica are you using? Could you post the output of `$Version`? I think `Compile` and friends was introduced in version 8, and if you are running version 7, it might not work. – abcd Jan 17 '12 at 03:18
  • $Version "7.0 for Microsoft Windows (32-bit) (November 10, 2008)" – zeroo Jan 17 '12 at 04:09
  • if the problem is the version of Mathematica will try to get the 8 I am very interested to solve this problem of generation of rational numbers thanks for your help so far – zeroo Jan 17 '12 at 04:20
  • Hi, I got the version 8 of mathematica and the program run ok I could help give the format that has the image above, the truth is a bit tangled code for me and I get lost easily – zeroo Jan 17 '12 at 13:38
  • ***@yoda these out there?? Or someone to help me – zeroo Jan 19 '12 at 01:37
2

Can you just type it in a grid? something like this: (you did not say what your a,b,c,d are supposed to be, if you clarify that, I can update this. I assume you will have some choices to pick from somewhere. This can be easily added.

enter image description here

t1 = "the value of ";
t2 = " is :  a)  b)  c)   d)";
a = {"1/2", "3/4", "8/9", "4/3"};
b = {"5/6", "5/6", "9/5", "7/9"};
choice = {"a) b) c) d)"};
r = Table[{i, t1, a[[i]] + b[[i]], t2}, {i, 1, Length[a]} ];
r = Insert[r, {" mid term exam", SpanFromLeft}, 1];
r = Insert[r, {" no cheating allowed", SpanFromLeft}, -1];
Grid[
 r,
 Frame -> {1 -> True, All}, Spacings -> {.4, 1}, Alignment -> Center
 ]

edit(1)

Here is also a demo using Mathematica to generate algebra quiz questions. May be this can give the OP more ideas:

http://demonstrations.wolfram.com/AlgebraQuiz/

Nasser
  • 12,849
  • 6
  • 52
  • 104
  • thanks for replying the code you wrote does not fit what I'm trying to do but thanks just gave me some looks anyway ideas.de editing my question above, that's what I'm look at the link you told me but it's not what I want, I had seen before – zeroo Jan 16 '12 at 18:28