Note: You are currently viewing documentation for Moodle 3.3. Up-to-date documentation for the latest stable version of Moodle is probably available here: Formulas: Examples.

Formulas: Examples: Difference between revisions

From MoodleDocs
No edit summary
Line 6: Line 6:
The Formulas question has no built-in function to display numbers with a given number of significant figures. However, it is easy to work out this function as the following variable assignment which works with any real number:
The Formulas question has no built-in function to display numbers with a given number of significant figures. However, it is easy to work out this function as the following variable assignment which works with any real number:


xr=x==0?x:round(x*pow(10,nsf-1-floor(log10(abs(x)))),0)*pow(10,-nsf+1+floor(log10(abs(x))));
<pre style="font-size:113%;width: 98%;">
xr=x==0?x:round(x*pow(10,nsf-1-floor(log10(abs(x)))),0)*pow(10,-nsf+1+floor(log10(abs(x))));
</pre>


where x is the number to be rounded, nsf the number of significant digits to keep and xr the rounded value.
where <span style="font-family: monospace;font-size:113%;">x</span> is the number to be rounded, <span style="font-family: monospace;font-size:113%;">nsf</span> the number of significant digits to keep and <span style="font-family: monospace;font-size:113%;">xr</span> the resulting rounded value.


<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:20px 0 25px;">
<div style="font-family:Lucida Sans Unicode;font-size:113%;color:#6c336d;margin:10px 0 10px;> Example</div>
This example deals with the display of the correct answers with different numbers of significant figures.
The Formulas question should look like this:
[[File:Formulas201712301427.png|680px]]
<div style="margin:20px 0 20px;">
[http://35.193.77.29/mod/quiz/view.php?id=152<span style="background-color:#f98012;box-shadow: 0 5px 10px #cbcbcb;border: none;color:white;padding: 8px 16px;text-align:center;text-decoration: none;cursor:pointer;">Play it</span>]   [[Formulas_question_type#Examples|Login info]]  ''(Open in new tab: Ctrl+Shift+Click)''
</div>
</div>
<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:20px 0 25px;">
<div style="font-family:Lucida Sans Unicode;font-size:113%;color:#6c336d;margin:10px 0 10px;> Example</div>


This example deals with the display of numbers written with a given number of significant figures.
This example deals with the display of numbers written with a given number of significant figures.
Line 20: Line 38:
[http://35.193.77.29/mod/quiz/view.php?id=152<span style="background-color:#f98012;box-shadow: 0 5px 10px #cbcbcb;border: none;color:white;padding: 8px 16px;text-align:center;text-decoration: none;cursor:pointer;">Play it</span>]   [[Formulas_question_type#Examples|Login info]]  ''(Open in new tab: Ctrl+Shift+Click)''
[http://35.193.77.29/mod/quiz/view.php?id=152<span style="background-color:#f98012;box-shadow: 0 5px 10px #cbcbcb;border: none;color:white;padding: 8px 16px;text-align:center;text-decoration: none;cursor:pointer;">Play it</span>]   [[Formulas_question_type#Examples|Login info]]  ''(Open in new tab: Ctrl+Shift+Click)''
</div>
</div>
 
</div>


[[#top|Back to top of page]]
[[#top|Back to top of page]]


[[Formulas_question_type|← FORMULAS QUESTION TYPE]]
[[Formulas_question_type|← FORMULAS QUESTION TYPE]]

Revision as of 06:21, 31 December 2017


Significant figures

"The significant figures of a number are digits that carry meaning contributing to its measurement resolution." (Reference: https://en.wikipedia.org/wiki/Significant_figures).

The Formulas question has no built-in function to display numbers with a given number of significant figures. However, it is easy to work out this function as the following variable assignment which works with any real number:

xr=x==0?x:round(x*pow(10,nsf-1-floor(log10(abs(x)))),0)*pow(10,-nsf+1+floor(log10(abs(x))));

where x is the number to be rounded, nsf the number of significant digits to keep and xr the resulting rounded value.

Example

This example deals with the display of the correct answers with different numbers of significant figures.

The Formulas question should look like this:

Formulas201712301427.png

Play it   Login info  (Open in new tab: Ctrl+Shift+Click)

Example

This example deals with the display of numbers written with a given number of significant figures.

The Formulas question should look like this:

Formulas201712301427.png

Play it   Login info  (Open in new tab: Ctrl+Shift+Click)

Back to top of page

← FORMULAS QUESTION TYPE