Rev 5947 | Rev 15107 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6133 | bpr | 1 | <h3>Random parameters in an interactive exercise</h3> |
2 | <p> |
||
23 | reyssat | 3 | The use of random parameters makes your exercise much more interesting, |
4 | because it will be a different exercise each time it is requested. |
||
6133 | bpr | 5 | </p><p> |
23 | reyssat | 6 | For example, the following line defines a parameter under the name of |
7 | <font color=blue><b>x1</b></font>, whose value will be a random integer |
||
8 | between -10 and 10 (inclusive): |
||
6133 | bpr | 9 | </p> |
23 | reyssat | 10 | <pre> |
11 | \integer{x1=random(-10..10)} |
||
12 | </pre> |
||
6133 | bpr | 13 | <p>This random parameter may then be called by the word |
5903 | bpr | 14 | <b><span class="tt wims_code_variable">x1</span></b>, in the statement, the replis, the hint and the solution. |
15 | That is, each word <span class="tt wims_code_variable">x1</span> in these texts will be replaced |
||
23 | reyssat | 16 | by the random value of the parameter. This substitution will also take |
17 | place in the definitions of other parameters which follow that of x1. |
||
6133 | bpr | 18 | </p><p> |
23 | reyssat | 19 | Suppose now that you have entered |
6133 | bpr | 20 | </p><pre> |
23 | reyssat | 21 | \integer{x1=random(-10..10)} |
22 | \integer{y1=\x1+3} |
||
23 | </pre> |
||
24 | in the field of the definition of parameters, and the question |
||
25 | <pre> |
||
26 | Compute the multiplication of \x1 by \y1. |
||
27 | </pre> |
||
28 | in the statement of the exercise. Suppose that for a certain request of |
||
6133 | bpr | 29 | the exercise, a random value <span class="wims_emph">-7</span> |
23 | reyssat | 30 | is attributed to \x1. Then the following parameter \y1 will take the value |
5755 | bpr | 31 | -4, and the statement of the exercise will be presented under the form <div class="wimscenter">Compute the multiplication of -7 by -4. |
32 | </div> |
||
5903 | bpr | 33 | You may then define a numerical reply in the name of <span class="tt">The product</span>, |
34 | having for the good solution <span class="tt wims_code_words">(\x1)*(\y1)</span>. (Remark that here |
||
23 | reyssat | 35 | the parentheses are necessary, because the substitution is done literarily.) |
5912 | bpr | 36 | <a id="list"></a> |
23 | reyssat | 37 | !if oefparm isitemof $special_parm |
38 | !changeto help/oefparm.phtml |
||
39 | !endif |
||
5912 | bpr | 40 | $table_header |
23 | reyssat | 41 | <caption>Some other examples of parameters |
42 | !href cmd=help&special_parm=$special_parm,oefparm#list [complete list] |
||
43 | </caption> |
||
5947 | bpr | 44 | $table_hdtr<th>Definition</th><th>Effect</th></tr> |
6133 | bpr | 45 | $table_tr<td class="tt wims_code_words">\real{x=random(-5..5)} |
5947 | bpr | 46 | </td><td>\x will be a random real number<br/>between -5 and 5 |
47 | </td></tr> |
||
6133 | bpr | 48 | $table_tr<td class="tt wims_code_words">\real{a=random(-5,-3,0.3,4)} |
5947 | bpr | 49 | </td><td>\a will be a real number taken randomly<br/>among -5,-3,0.3 and 4 |
50 | </td></tr> |
||
6133 | bpr | 51 | $table_tr<td class="tt wims_code_words">\complex{z=(1+2*i)^3} |
5947 | bpr | 52 | </td><td>\z will be the complex number (1+2*i)^3 |
53 | </td></tr> |
||
6133 | bpr | 54 | $table_tr<td class="tt wims_code_words">\text{sign=random(+,-)} |
5947 | bpr | 55 | </td><td>\sign will be a random sign: + ou - |
56 | </td></tr> |
||
6133 | bpr | 57 | $table_tr<td class="tt wims_code_words">\integer{n=3*exp(\a)} |
5947 | bpr | 58 | </td><td>\n will be the closest integer to 3*e<sup>\a</sup> <br/>(it depends on |
23 | reyssat | 59 | the value of \a) |
5947 | bpr | 60 | </td></tr> |
6133 | bpr | 61 | $table_tr<td class="tt wims_code_words">\function{f=random<br/> (x^2+1,sin(x),log(x))} |
5947 | bpr | 62 | </td><td>\f will be a random function: either x^2+1,<br/>or sin(x), or |
23 | reyssat | 63 | log(x) |
5947 | bpr | 64 | </td></tr> |
6133 | bpr | 65 | $table_tr<td class="tt wims_code_words">\real{a=evalue(x^2+sin(y),x=3,y=4)} |
5947 | bpr | 66 | </td><td>Evaluation of the function x^2+sin(y),<br/> |
23 | reyssat | 67 | for x=3, y=4 |
5947 | bpr | 68 | </td></tr> |
6133 | bpr | 69 | $table_tr<td class="tt wims_code_words">\real{r=solve(x^3-3*x+1,x=0..1)} |
5947 | bpr | 70 | </td><td>\r will the the simple root of x^3-3x+1 between 0 and 1 |
71 | </td></tr> |
||
6133 | bpr | 72 | $table_tr<td class="tt wims_code_words">\function{h=simplify(x^5*y^3*x^2/y)} |
5947 | bpr | 73 | </td><td>Simplified expression: x<sup>7</sup>y<sup>2</sup> |
74 | </td></tr> |
||
6133 | bpr | 75 | $table_tr<td class="tt wims_code_words">\function{g=diff(sin(x)+cos(y),x)} |
5947 | bpr | 76 | </td><td>\g will the the derivative of sin(x)+cos(y) with respect to x |
77 | </td></tr> |
||
6133 | bpr | 78 | $table_tr<td class="tt wims_code_words">\function{F=int(x^2+3*x+1,x)} |
5947 | bpr | 79 | </td><td>\F will an antiderivative of x^2+3*x+1,<br/> |
23 | reyssat | 80 | the constant term being not garanteed to be always the same |
6133 | bpr | 81 | !!$table_tr<td class="tt wims_code_words">\function{F=int(t^2+3*t+1,t=1..x)} |
5947 | bpr | 82 | !! </td><td>\F will the antiderivative of x^2+3*x+1 with g(1)=0 |
83 | </td></tr> |
||
6133 | bpr | 84 | $table_tr<td class="tt wims_code_words">\real{a=int(t^2+3*t+1,t=0..1)} |
5947 | bpr | 85 | </td><td>\a will the numerical integral of x^2+3*x+1 from 0 to 1 |
86 | </td></tr> |
||
6133 | bpr | 87 | $table_tr<td class="tt wims_code_words">\text{f=htmlmath(2*x^2+3*x)} |
5947 | bpr | 88 | </td><td>\f will be rendered in html as: 2x<sup>2</sup>+3x |
89 | </td></tr> |
||
6133 | bpr | 90 | $table_tr<td class="tt wims_code_words">\text{f=texmath(2*x^2+3*x)} |
5947 | bpr | 91 | </td><td>\f will be the TeX source for the expression. |
92 | </td></tr> |
||
6133 | bpr | 93 | $table_tr<td class="tt wims_code_words">\integer{n=items(a,b,c,d,e,f)} |
5947 | bpr | 94 | </td><td>\n will be the number of items (here it is 6) in the list |
23 | reyssat | 95 | {a,b,c,d,e,f} |
5947 | bpr | 96 | </td></tr> |
6133 | bpr | 97 | $table_tr<td class="tt wims_code_words">\text{i=item(3,a,b,c,d,e,f)} |
5947 | bpr | 98 | </td><td>\i will be the item number 3 of the list |
23 | reyssat | 99 | {a,b,c,d,e,f} (hence c). |
5947 | bpr | 100 | </td></tr> |
6133 | bpr | 101 | $table_tr<td class="tt wims_code_words">\text{s=shuffle(6)} |
5947 | bpr | 102 | </td><td>\s will be the list of 6 integers 1,2,...,6, in random order. |
103 | </td></tr> |
||
6133 | bpr | 104 | $table_tr<td class="tt wims_code_words">\text{s=shuffle(a,b,c,d,e)} |
5947 | bpr | 105 | </td><td>\s will be the letters {a,b,c,d,e} in random order. |
106 | </td></tr> |
||
6133 | bpr | 107 | $table_tr<td class="tt wims_code_words">\matrix{m=1,2,3<br/>4,5,6<br/>7,8,9} |
5947 | bpr | 108 | </td><td>\m will be the matrix of 3 rows and 3 columns. |
109 | </td></tr> |
||
6133 | bpr | 110 | $table_tr<td class="tt wims_code_words">\text{t=asis(How do you do? item(1,2,3))} |
5947 | bpr | 111 | </td><td>The string as it is, with no transformation nor conditionality. |
112 | </td></tr> |
||
113 | $table_end |
||
23 | reyssat | 114 | |
4091 | bpr | 115 | Conditional parameters: You may write |
116 | <pre> |
||
117 | \text{ttt=_condition?_def1} |
||
118 | \text{ttt=_condition?_def1:_def2} |
||
119 | </pre> |
||
23 | reyssat | 120 | <p> |
5903 | bpr | 121 | In this case, <span class="tt">ttt</span> will be set to <span class="tt">_def1</span> if |
122 | <span class="tt">_condition</span> is true, or to <span class="tt">_def2</span> otherwise (in the second |
||
23 | reyssat | 123 | syntax). |
124 | !href target=wims_mhelp cmd=help&special_parm=if List of conditions |
||
5947 | bpr | 125 | </p><p> |
23 | reyssat | 126 | The relative positionning of the definition and the statement is important: |
127 | if a variable is defined AFTER the statement, the evaluation of the variable |
||
128 | will take place only AFTER the user has replied to the question. In this |
||
5903 | bpr | 129 | case, the definition may involve user replies, via <span class="tt wims_code_variable">\reply1</span>, |
130 | <span class="tt wims_code_variable">\reply2</span>, etc. And the variable can be used in testing |
||
23 | reyssat | 131 | conditions or feedbacks. |
5947 | bpr | 132 | </p> |