Units in STACK

Units in STACK

by Stephan Bach -
Number of replies: 2

Hello,

I have a question about how to handle scientific units in STACK.  If I add

stack_unit_si_declare(true);
to the question variables field and then for example define
R:stackunits(12,ohm);
U:stackunits(12,V);
ta:U/R;

\(I=1\, \mathrm A\) will be accepted as a true answer. But the model answer, shown to the student, is \(1\, \frac{\mathrm V}{\Omega}\), which is not what I want.

What I'm doing so far to go round this is to define all the variables without units first and then attach the units I want in the end:


R:12;
U:12;
ta:U/R;

R:stackunits(R,ohm);
U:stackunits(U,V);
ta:stackunits(ta,A);

I'm wondering if there is a better and shorter way how to solve this. Any ideas?

Stephan.



Average of ratings: -
In reply to Stephan Bach

Re: Units in STACK

by Christopher Sangwin -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Stephen, 


This is a good question. The units system in STACK is very simple.  The comparisons work by converting back to the base scientific units.  Other functions, allowing you to manipulate units are very simple.  At the moment we don't distribute "/" over "stackunits".  The function "stackunits" is an ephemeral form, just representing units.  In particular you might expect the result of 

R:stackunits(12,ohm);
U:stackunits(12,V);
ta:U/R;
to be

stackunits(1,V/ohm)
At this point is isn't!  

However, if you have 

ta:stack_unit_si_to_si_base(stackunits(1,V/ohm));

then this is simplified to "A".

I think a "general units simplifier" would be a useful addition to the functionality.  You can see the current code here:

https://github.com/maths/moodle-qtype_stack/blob/master/stack/maxima/stackunits.mac

If anyone would like to work on this aspect of the units, I'd be delighted to receive some improved code.

My advice at the moment Stephen is to use "stackunits" at the very last step, just before you show the expression to students.

Chris


Average of ratings: Useful (2)