This is great module. I look forward to getting it up and running on my site.

I would like to be able to ask math questions using a mix of randomly generated numbers and randomly selected values from an set of fixed values. Is this possible?

For example, a physics question could ask a student to calculate the weight (in Newtons) of an object given its mass and the gravity of the planet it is on. The mass could be calculated using a=random() then a=round(a*995+5,0) to create a mass between 5 and 1000 g.
The second variable needed is the force of gravity. If the question allows the object to be on either Earth, Mars or our Moon, each new iteration of the question would need to chose a planet. using PHP the process could be done using something like the following:

$planet = mt_rand(1,3);
  if ($planet = 1)  {   // Earth
    $gravity = 9.8 ;
  } elseif ( $planet = 2 ) {   // the Moon
    $gravity = 1.6;
  } else {
    $gravity = 3.7; // Mars
  }

$gravity would then be used to calculate the ans value.

Comments

jvdkolk’s picture

What if you tried something like:

a=random()
g=1.6 + round(a+0.5-0.333)*2.1 + round(a+0.5-0.666)*6.1

What I did: I calculated the step sizes between the g's (so from 1.6 --> 3.7 = 2.1, from 3.7 --> 9.8 = 6.1).

The formula starts with 1.6,
1) it will add 2.1 to 1.6 if the random a is between 0 and 0.333 (so g will be 1.6+2.1 = 3.7)
2) it will add another 6.1 if the random a is between 0 and 0.666 (so g will be 1.6+2.1+6.1 = 9.8)

So in fact,
when a <= 0.333, g will be 1.6
when 0.333 <= a <= 0.666, g will be 3.7
when 0.666 <= a <= 1, g will be 9.8

amstar’s picture

rekor,

Thanks for the reply. Your solution will allow me to do exactly what I need with the numbers.

How about if I added the complication of wanting to assign a variable to hold the name of the planet so that could be used in the question as well?

In the php example above, I'd assign a new variable $planet_name to either "Earth", "Mars", or "the Moon" depending on the value of $planet.

$planet_name could then be used in the question:

echo 'Given that the force due to gravity is ' .$gravity. ' on ' .$planet_name. ', what is the weight in Newtons of an object with a mass of ' .$mass. '?';
jvdkolk’s picture

dear amstar,

I do not think that is possible right now..

But of course you could also rephrase your question into 'On the planet Amstaria, the gravity is', and then use the random number.

amstar’s picture

Category: support » feature

I'd like to make this a feature request. Using fictional names is a good work around but that level of abstraction is not ideal. Especially for adult learners who value applied knowledge.

jvdkolk’s picture

Ok. So basically what you are asking it the ability to map numbers created with a math expression to text labels, and the ability to add these text labels in the question text.

The ClosedQuestion XML is would then become something like this:

<question type="OPTION"> 
  <text>
   You are now on the <textlabelresult id="planets" mathresult="g">
  </text>
  ...
  <matheval expression="a=random()" />
  <matheval expression="g=1.6 + round(a+0.5-0.333)*2.1 + round(a+0.5-0.666)*6.1" />
  <textlabel id="planets">
    <trigger value="1.6">Moon</trigger>
    <trigger min="3.7" max="3.7">Mars</trigger>
    <trigger regexpmatch="^9.8$">Earth</trigger>
  </textlabel>
  ...
</question>

It seems to be a quite interesting feature to me. The more users/use cases we can find supporting it, the more likely that this feature will be implemented :).

amstar’s picture

Yes. That is the idea. I can not speak for other users but this structure is one I make use of often in introductory science. Other questions that I have written using straight PHP are:

  • calculating how many grams of a compound to add to a set volume to get a desired molarity. This one would need to link formula weight to the compound
  • refractive index when light passes from one medium to another. For this one you would need two pairs, one for the initial medium and one for the final
  • buoyancy force on an object of known mass and density when submerged in different liquids.

In all of these cases I don't go crazy with options. I just try to have 3 or 4 sets for the system to select from. It makes the questions a little more engaging and complicates the math a bit.

HylkeVDS’s picture

It's a very interesting feature, I'll have a look if I have time to implement it.

HylkeVDS’s picture

Status: Active » Needs review

I've implemented the feature as follows (small example):

<matheval e="a=random()"/>
<matheval e="a=round(a*10, 2)"/>
<textlabel id="testLabel">
  <triggernumber min="7">Large</triggernumber>
  <triggernumber max="3">Small</triggernumber>
  <triggernumber>Medium</triggernumber>
</textlabel>
<text>The value of a is <textlabelresult id="testLabel" variable="a"/> (<mathresult expression="a"/>).</text>

It is also possible to check against the users answer and use that in feedback.

Let me know what you think :)

amstar’s picture

HylkeVDS - The textlabel trigger is a great added feature. I've used it quite a bit. How hard would it be to get the trigger to return a variable instead of a text field?

The reason I ask is that I'd like the ability to add some more dynamism into each question. As an example, here is a question I am working on.

  <matheval expression="a=random()" store="1" />
  <matheval expression="a=round(a*400+100,0)" />
  <matheval expression="b=random()" store="1" />
  <matheval expression="b=round(b*0.15+0.1,2)" />
  <matheval expression="b=round(b*a,0)" />
  <matheval expression="paramToAsk=random()" store="1" />
  <matheval e="paramToAsk=floor(paramToAsk*4)" />
  <textlabel id="testLabel">
    <triggernumber max="0">what proportion of the alleles in the population are recessive?</triggernumber>
    <triggernumber max="1">what proportion of the alleles in the population are dominant?</triggernumber>
    <triggernumber max="2">what proportion of the population is homozygous dominant?</triggernumber>
    <triggernumber>what proportion of the population is heterozygous?</triggernumber>
  </textlabel>
  <matheval expression="ans=VARIED" /> ************************** ans will differ predictably based on the value of paramtoAsk **************************
  <matheval expression="min=ans-0.01" />
  <matheval expression="max=ans+0.01" />
  <text><p>Given a population rabbits whose ear length is controlled by a single gene and an allele for long ears (L) that exhibits complete dominance. If a population  of <mathresult expression="a" /> rabbits contains <mathresult expression="b" /> short eared individuals, <textlabelresult id="testLabel" variable="paramToAsk"/></p>

The question creates a population of between 100 to 500 rabbits. It then makes between 10 and 25% of them homozygous recessive for the trait of interest.

Closed question makes it very easy to set up a question that asks any one of the following questions:

  1. what proportion of the alleles in the population are recessive?
  2. what proportion of the alleles in the population are dominant?
  3. what proportion of the population is homozygous dominant?
  4. what proportion of the population is heterozygous?

But, I'd like to structure a single question to dynamically chose one of these options each time the question is reset.

Following the structure of the textlabel element, what I'd like to do is find the answer dynamically using something like this:

  <dynamicVarible id="answer">
    <triggernumber max="0">ans = sqrt(b)</triggernumber>
    <triggernumber max="1">ans = 1-sqrt(b)</triggernumber>
    <triggernumber max="2">ans = pow(1-sqrt(b),2)</triggernumber>
    <triggernumber>ans = 2*(sqrt(b))*(1-sqrt(b))</triggernumber>
  </dynamicVarible>

I can approximate this behavior with the solution given by koosvdkolk in comment #1 but it is very cumbersome.

HylkeVDS’s picture

Have you tried

<dynamicVarible id="answer">
    <triggernumber max="0"><mathresult expression="ans = sqrt(b) "/></triggernumber>
    <triggernumber max="1"><mathresult expression="ans = 1-sqrt(b) "/></triggernumber>
    <triggernumber max="2"><mathresult expression="ans = pow(1-sqrt(b),2) "/></triggernumber>
    <triggernumber><mathresult expression="ans = 2*(sqrt(b))*(1-sqrt(b)) "/></triggernumber>
  </dynamicVarible>

I don't know if that will work though. It's been too long since I had a look at the code.

jvdkolk’s picture

Status: Needs review » Closed (won't fix)

More information is needed from amstar...

amstar’s picture

I am sorry for the delay in replying. I did not notice HylkeVDS's comment (#10) and have been using the solution given by koosvdkolk in comment #1, aided by a small javascript script that helps me generate the multi-step rounding equations.

This has allowed me to write dynamic fillblanks with math problems with as many variations as I need.

I have recently started looking at the other question types offered by closed question and am interested in creating dynamic question for these question types as well.

I can use the single hotspot example available at the Wageningen MultiMedia Research Center (http://wmmrc.nl/drupal-modules/closedquestion/example-questions/hotspot-...) to illustrate. As written, the answer is always the enzyme-substrate complex.

It would be great if the question could vary by choosing among the following prompts each time the question was reset:

1 - Point out the enzyme-substrate complex
2 - Point out the enzyme-product complex
3 - Point out the free enzyme

The textlabel feature allows me to create variable text:

<matheval expression="correctFeature=random()" store="1" />
     <textlabel id="featureName">
          <triggernumber max="0.33">enzyme-substrate</triggernumber>
          <triggernumber max="0.66">enzyme-product</triggernumber>
          <triggernumber>free enzyme</triggernumber>
     </textlabel>

The textlabel feature also allows me to generated the question text:
<text>Point to the <textlabelresult id="featureName" variable="correctFeature" />.</text>

What I have been unable to figure out is how to make the correct answer mapping vary based on the question variation. I think all of the features needed exist within the module, but I can not get them to work inside the hotspot question type. If range would work for hotspots the way it does for fillblanks, I could do something like this:

<mapping correct="1">
    <or>
        <and><match hotspot="a" /><range variable="correctFeature" minval="0" maxval="0.33" /></and>
        <and><match hotspot="b" /><range variable="correctFeature" minval="0.33001" maxval="0.66" /></and>
        <and><match hotspot="a" /><range variable="correctFeature" minval="0.66001" maxval="1" /></and> 
    </or>
    <feedback>Correct!!</feedback>
</mapping>

I've tried this but am unable to use range without inlineChoice or value attributes.

amstar’s picture

Status: Closed (won't fix) » Needs review

Changing status to invite comment.

  • HylkeVDS committed fcffc12 on varexport
    Issue #1231310 by HylkeVDS: Added TextLabel feature.
    
    
jvdkolk’s picture

Issue summary: View changes
Status: Needs review » Closed (fixed)