Units conversions in formulas questions type

Units conversions in formulas questions type

by Jean-Michel Védrine -
Number of replies: 4

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 :

good response 1
Here we see a very good student (me big grin) giving a good response
But what if we don't use m/s for the unit ? Let's try :

good answer 2
Another one :


A perfectly ridiculous one but I have taken a screenshot just before clicking submit to show you that :

  1. the system display in the blue popup how he interpret my response
  2. you can use scientific notation to enter numbers
  3.  u is used for 10-6 prefix rather than the greek letter $$ \mu $$

good response 4
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.
good response 7
The system now understand our new unit big grin ! (wich is certainly not a SI one big grin !)
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.

Average of ratings: Useful (2)
In reply to Jean-Michel Védrine

Re: Units conversions in formulas questions type

by Pierre Pichet -

Hi Jean-Michel,

Just to say that I share your enthousiasm to Hon Wai Lau work and appreciate you own work on Moodle.wink

Pierre

P;S; More next week on return from summer holidays.

In reply to Pierre Pichet

Re: Units conversions in formulas questions type

by Jean-Michel Védrine -

Hello Pierre,

For me in fact, even if I had used formulas questions  before on my Moodle 1.9 website, I didn't realized it's full potential until I worked on the code.

So I tought that maybe other Moodle userstoo don't realize all formulas questions possibilities and that some posts will permit formulas to gain some more visibility.

Of course as a math teacher, I don't use units very often, my teaching is more about roots, polynomials, equations and matrix but I also teach statistics and as my students follow bussiness studies I like to give them more practical questions so I will surely define conversion rules between euros, dollars and other currencies, even if I must fix exchange rates wich in these days is not very reallistic !

Let me also thank you for all your work on Moodle.

A few years ago I used to do some Moodle coding, then real life has taken all my free time. I have now managed to get some free time again by stopping a lot of administrative and unpleasant  tasks. I enjoy a lot to be able to do some Moodle programing work again and to read your contributions, Joseph's, Itamar's, Adriane's and many other. Fortunately Moodle 2.x releases have not stopped that !

In reply to Jean-Michel Védrine

Re: Units conversions in formulas questions type

by hon wai lau -

Thanks for the great tutorial on the unit smile, it is better my documentation. It has already covered all usages of the unit system, so hope that someone find it useful. Here are just few more notes:

  • Adding your own rule is welcomed. As I am not familiarize with other unit system, such as the use of inch, so I have only added the common SI unit (which are actually only units used in introductory physics courses). We may add others system to the file to make it more convenient to other without redefining rule set each time.
  • The "other rule" is for convenient. For repeated definition, it is better to add it to the file so that it is easier to use and understand by both teachers and students.
  • It is the reason that why the student should get 0 mark if they type the wrong answer. Grading the number alone does not make sense.
  • Though they are written unit in that way in the homework. It takes some times for the students to understand that they can use different prefix mixed, unless they have skimmed the conversion table.
In reply to Pierre Pichet

Re: Units conversions in formulas questions type

by hon wai lau -

Hello Pierre,

If you are interested, you may want to take a look of the unit system in the formulas question type. It is the most sophisticated system I have ever developed smile