Using scientific notation when displaying calculated questions

Using scientific notation when displaying calculated questions

by Gábor Katona -
Number of replies: 10
I would like to set, that numbers below a certain limit appear in scientific notation in calculated questions. For example if the dataset is 0-0.01 with 5 decimal places, than I would like to have generated values below 0.001 to appear as e.g. 4*10-4 instead of 0.0004. Is it possible?
Average of ratings: -
In reply to Gábor Katona

Re: Using scientific notation when displaying calculated questions

by Pierre Pichet -
Hi Gabor,
You can write your number as 4.0e-4.

Pierre

In reply to Pierre Pichet

Tárgy: Re: Using scientific notation when displaying calculated questions

by Gábor Katona -
I now this, but when displaying the question, moodle uses the simple decimal notation. So if the I give the range as 0-1e-7, decimal places 9, then moodle would display 0.000000045 instead of 4.5e-8.
In reply to Gábor Katona

Re: Tárgy: Re: Using scientific notation when displaying calculated questions

by Pierre Pichet -
The display of decimal (or real) number is controlled by some local settings of the PHP math library used as far as I understand.
So it varies and furthermore how could set the frontier between the two representation that will fit to all Moodle users?

Pierre

In reply to Pierre Pichet

Tárgy: Re: Tárgy: Re: Using scientific notation when displaying calculated questions

by Gábor Katona -
I am looking for a question or quiz based setting, because displaying 0.000000000045 is not to convenient.
In reply to Gábor Katona

Re: Tárgy: Re: Tárgy: Re: Using scientific notation when displaying calculated questions

by Pierre Pichet -
There is no such question or quiz based setting,
Pierre
In reply to Gábor Katona

Re: Tárgy: Re: Tárgy: Re: Using scientific notation when displaying calculated questions

by Pierre Pichet -
Hi Gabor,
I did not notice that you set for decimal places.
Just set for significant figures and the display will be converted in the X.0000E-xx format.
Pierre


In reply to Pierre Pichet

Re: Tárgy: Re: Tárgy: Re: Using scientific notation when displaying calculated questions

by Andrea Sella -
I'm joining the conversation late having almost gone crazy trying to write some simple chemistry/physics questions involving numbers that have small mantissa's but large exponents e.g 6.02E23

Can you clarify what you mean by "set for significant figures". Is that in the actual calculated question or is it a global setting for the course or even for the entire Moodle environment?


In reply to Andrea Sella

Re: Tárgy: Re: Tárgy: Re: Using scientific notation when displaying calculated questions

by Pierre Pichet -
Hi Andrea,

Being a chemist myself, I had the same problem.
The significant figures is related to answer parameters
Correct answer shows (select element with a number)
Format (select element decimals or significant figures)

You cannot easily generate dataitems for small numbers because of actual limitations of the generator code (maximum decimal of 10) but you can do it for large number if you set the minimum and maximum values with e notation i.e. Minimum 1.0E23 and Maximum 2.0E23.

However you can use the following trick for small numbers.

You generate values for a {a} wild card between say 1.0 and 9.9999 with 4 decimals and in your question text you write something like
{a}E-14
which will appears to the students as i.e 5.899E-14

You just take care in your answers equation to multiply {a} by 1.0E-14 so that it reflects the real value.

Pierre

In reply to Pierre Pichet

Re: Tárgy: Re: Tárgy: Re: Using scientific notation when displaying calculated questions

by Joshua Bragg -
I just attempted to take this one step further by setting up the given number in my problem as {N}e{EXP} and my formula as {N}e{EXP}/6.626e-34/1000 using Moodle 1.9.3

I get this error when I ask it to make a new data set.
Parse error: syntax error, unexpected T_DNUMBER in D:\server\moodle\question\type\calculated\questiontype.php(880) : eval()'d code on line 1

Fatal error: Maximum execution time of 60 seconds exceeded in D:\server\moodle\question\type\calculated\questiontype.php on line 1183

I'm assuming that the system wasn't built to handle variable values with the "e" notation?

However, if I write the formula instead as {N}*pow(10,{EXP})/6.626e-34/1000, then everything works out just fine.

One odd thing is that this adds parentheses in an odd place in my problem text.
{N}x10{EXP} becomes 2.42x10(-18). But that is not a big deal. Is this because I'm using a negative number?


In reply to Joshua Bragg

Re: Tárgy: Re: Tárgy: Re: Using scientific notation when displaying calculated questions

by Pierre Pichet -

Hi Joshua,

The system is not able to handle something like {N}e{EXP}  as e is not a PHP function.

However, it should be able to detect such errors in the formula.

As for using scientific notation you can set the generator with min 2.3e-2 and max 6.7e-1. The generated values will be OK.

However there is an actual limit of 9 decimals in the values generated so 1e-16 will not work.

Instead use the following trick .

Generate values between 1 and 10 for say {N} wild card and display the parameter in the question text as {N}E-16.

The question text will show the rigth value for the students and you have to set your formula by multipliying {N} * 1.0e-16.

Pierre