As I said in another message I will try to show how sophisticated the unit system in Hon Wai Lau's formulas question type is.
For that I will use a simple example formulas question (This example is pretty similar to one in the example-new.xml file you can download on Hon Wai Lau website, but if you are not very familiar with formulas questions, I think it would be better to try to type it yourself)
Question name : Example speed
Random variables :
v = {20:100:10};
dt = {2:6};
Global variables
s = v*dt;
Question text : empty
And we define only 1 Subquestion answer :
Default answer mark : 1
Local variables : empty
Answer type : numeric
Answer : v
Grading crieria : Relative error < 0.01
Unit m/s
Placeholder name : empty
subquestion text : If a car travel {s} m in {dt} s, what is the speed of the car?<br />
Extra options: don't change the defaults
Save your work and open a preview, you should see something like :
Here we see a very good student (me ) giving a good response
But what if we don't use m/s for the unit ? Let's try :
Another one :
A perfectly ridiculous one but I have taken a screenshot just before clicking submit to show you that :
- the system display in the blue popup how he interpret my response
- you can use scientific notation to enter numbers
- u is used for 10-6 prefix rather than the greek letter $$ \mu $$
of course some of you are thinking : but I certainly don't want to accept micrometers as a distance unit for that problem. More on that later
A last try :
Hum, formulas don't want my km/h unit ? Why ? How to allow an unit that is not already in the conversion system ?
To better understand I will show you some lines of formulas code but you don't need to be a programmer to understand :
$basic_unit_conversion_rules[0] = array('None', '');
$basic_unit_conversion_rules[1] = array('Common SI unit','
m: k c d m u n p f;
s: m u n p f;
g: k m u n p f;
mol: m u n p;
N: k m u n p f;
A: m u n p f;
J: k M G T P m u n p f;
J = 6.24150947e+18 eV;
eV: k M G T P m u;
W: k M G T P m u n p f;
Pa: k M G T P;
Hz: k M G T P E;
C: k m u n p f;
V: k M G m u n p f;
ohm: m k M G T P;
F: m u n p f;
T: k m u n p;
H: k m u n p;
');
So basicaly 2 converstion rules are already programmed : "None" and "common SI"
You choose wich one you want in the "Extra options part" of the question editing screen
- If you choose none no conversion rule is defined and the student must use the one you defined when you created the answer.
- If you choose "Common SI" all units in the previous table will be accepted, that mean for instance that for distance, the base unit is m and accepted prefixes are k c d m u n p f so this is why km and um are accepted.
This is also valid not only for the "basic" unit m but also for a composite" unit like km/s (equivalent to km s^(-1) note the space for unit multiplication) or km^2.
But this is not the end.
Edit your question and add
1 m = 3.28083 feet
in the "other rules" field of the subquestion answer (you will have to use the nearby checkbox to make this field appear because less used fields are cached by default to not clutter too much the edit question form). Save and open preview.
The system now understand our new unit ! (wich is certainly not a SI one !)
So we can defined additional rules in the other rules input field.
you can also edit the question/type/formulas/conversion_rules.php and define your own system of conversion rules (for instances if you teach to very young pupils you may want to disallow um or nm)
Hon Wai Lau ask you to define your own rules with numbers greater than 99 as $basic_unit_conversion_rules[100] =
because numbers 0 to 99 are reserved.