Subversion Repositories wimsdev

Rev

Rev 2448 | Rev 4091 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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