5
$\begingroup$

I try to help my children in their subjects, I built a small code so that it has as output questions regarding the equation of the line, but I have not been able to modify it so that the result comes out randomly a) parallel b) perpendicular and the other thing I get the minus sign to come out randomly but when it is +, I don't know how to write it and it comes out + -, would you be so kind to help me improve the code and maybe the numbered exercises come out Thanks in advance

a := RandomInteger[{1, 10}];
b := RandomInteger[{1, 10}];
c := RandomInteger[{1, 10}];
(*ax+by+c=0*)
(*dx+ ey+f=0*)

d := RandomInteger[{1, 10}];
e := RandomInteger[{1, 10}];
f := RandomInteger[{1, 10}];
g := RandomInteger[{0, 1}];
Table [Print [" Find 'k' so that the line " , (-1)^(g + 1)*a, 
"x+", (-1)^(g + 1)*b, "y+" , (-1)^(g + 1)*c  , 
"=0 be perpendicular/parallel to the line"  , (-1)^(g + 1)*d, 
 "x+(", ((-1)^(g + 1)*e), "+k)y+" , (-1)^(g + 1)*f , "=0 " ], {i, 1, 
 20}]
$\endgroup$
3
  • 1
    $\begingroup$ For the issue of comes out + -, this needs addition check, since you have hardocded x+ in there and the random number sometimes comes negative with - in it already. So you need to add an extra check to only use + when the random number is positive and not negative so not to get the double sign. I can add this later. Just need to make some coffee now first. $\endgroup$
    – Nasser
    Sep 24 at 0:37
  • 1
    $\begingroup$ fyi, added the check for the +- issue. $\endgroup$
    – Nasser
    Sep 24 at 1:04
  • $\begingroup$ Not related to the code but as someone that started loving mathematics after I started understanding it in university, I think I would have seriously hated math if I had to use the same method 20 times or even more than 5 times maybe. My guess is less than 3 maybe 4 is enough if the concepts and mechanisms are understood. Also my guess is that being stuck in straight forward procedures could lower imagination or gives false ideas as to what solving math problems is like at a higher level. In principle I probably should not give my personal opinion but it was hard for me to not write this. $\endgroup$ Sep 24 at 18:42

2 Answers 2

6
$\begingroup$

May be

a := RandomInteger[{1, 10}];
b := RandomInteger[{1, 10}];
c := RandomInteger[{1, 10}];
(*ax+by+c=0*)
(*dx+ey+f=0*)

d := RandomInteger[{1, 10}];
e := RandomInteger[{1, 10}];
f := RandomInteger[{1, 10}];
g := RandomInteger[{0, 1}];

And now

data = Reap@Table[
    z0 = (-1)^(g + 1)*a;
    z1 = (-1)^(g + 1)*b;
    z2 = (-1)^(g + 1)*c;
    z3 = ((-1)^(g + 1)*e);
    z4 = (-1)^(g + 1)*f;
    z5 = (-1)^(g + 1)*d;
    
    sign1 = If[z1 < 0, "", "+"];
    sign2 = If[z2 < 0, "", "+"];
    sign3 = If[z3 < 0, "-", "+"];
    sign4 = If[z4 < 0, "", "+"];
    Which[z0 == 1, z0 = "", z0 == -1, z0 = "-"];
    Which[z1 == 1, z1 = "", z1 == -1, z1 = "-"];
    Which[z5 == 1, z5 = "", z5 == -1, z5 = "-"];
    
    par = If[RandomInteger[{0, 1}] == 1, "parallel", "perpendicular"];
    Sow[{i, 
      Row[{" Find 'k' so that the line ", z0, "x ", sign1, z1, "y ", 
        sign2, z2, " = 0 be ", par, " to the line ", z5, "x ", sign3, 
        "(", z3, "+k)y ", sign4, z4, "=0 "}]}], {i, 1, 20}];

Grid[data[[1]], Frame -> All, Alignment -> Left, 
 FrameStyle -> LightGray]

enter image description here

ps. too much HW's for your kids. Take it easy on them :)

$\endgroup$
7
  • $\begingroup$ ,thanks for the answers, ha ha that's the math they see in high school, could you add the random alternation of the words "parallel" and "perpendicular" to the code and if possible the numbering of the exercises in the form 01,02, 03 .....10,11,12....(only if it can appear x and not 1x) in advance very grateful $\endgroup$
    – padre
    Sep 24 at 1:23
  • $\begingroup$ I run it in MMA 13 and it does not display anything ???? $\endgroup$
    – padre
    Sep 24 at 1:30
  • $\begingroup$ thanks,is missing a "hair" in exercises 4 and 5 and others at the end it continues to appear + - could you add what is missing if I like what I asked you for x to appear and not 1x, -x and not -1x $\endgroup$
    – padre
    Sep 24 at 1:37
  • $\begingroup$ sorry for the inconvenience, I was reviewing your spreadsheet and looking at exercises 8,9,14,18... there is a small mistake in 8, for example, it should say 6x at the beginning and not 6+x, in the others it is similar and a sign is missing in between $\endgroup$
    – padre
    Sep 24 at 1:55
  • 1
    $\begingroup$ Can you try the update I just posted now (version 50 :) ? You should not see any sign anything in the output. $\endgroup$
    – Nasser
    Sep 24 at 2:23
2
$\begingroup$

I didn't want to deal with expression ordering, but how could I forget that Mathematica formats equations by default!

Clear[a, s1, s2]
a := RandomChoice[Range[-10, -1]~Join~Range[1, 10]]
s1 := ToString@ (a x + a y) <> " " <> 
  ToString@NumberForm[a, NumberSigns -> {"-", "+"}] <> " = 0"
s2 := ToString@ (a x + (a + k) y) <> " " <> 
  ToString@NumberForm[a, NumberSigns -> {"-", "+"}] <> " = 0"
Table[
  {StringPadLeft[#, 2] &@ToString@i, 
   StringForm["Find 'k' so that the line `` be `` to the line ``.",
    s1, pp, s2]
   },
  {i, 10}
  ] // TableForm

enter image description here


Original

a := RandomChoice[Range[-10, -1]~Join~Range[1, 10]]
pp := RandomChoice[{"perpendicular", "parallel"}]
cfull := ToString@NumberForm[a, NumberSigns -> {"-", "+"}];
cmid := With [{a = a}, 
  If[a == -1, "-", 
   If[a == +1, "+", 
    If[a > 1 || a < -1, 
     ToString@NumberForm[a, NumberSigns -> {"-", "+"}]]
    ]]]
cfront := 
 With [{a = a}, 
  If[a == -1, "-", If[a == +1, "+", ToString@NumberForm[a]]
   ]]
cbracket := 
 With [{a = a}, 
  If[a == -1, "-1", 
   If[a == +1, "1", ToString@NumberForm[a, NumberSigns -> {"-", "+"}]]]
  ]
Table[
  {StringPadLeft[#, 2] &@ToString@i, 
   StringForm[
    "Find 'k' so that the line ``x ``y `` = 0 be `` to the line ``x \
+(``+k)y `` = 0.",
    cfront, cmid, cfull, pp, cfront, cbracket, cfull
    ]},
  {i, 10}
  ] // TableForm

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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