Difference between revisions of "Formulas: More examples"

Jump to: navigation, search
(Significant figures)
(References)
 
(35 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
''"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 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:
+
The Formulas question has no built-in function to display values 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:
  
<pre style="font-size:113%;width: 98%;">
+
<pre style="font-size:113%;width: 97%;">
 
xr=x==0?x:round(x*pow(10,nsf-1-floor(log10(abs(x)))),0)*pow(10,-nsf+1+floor(log10(abs(x))));
 
xr=x==0?x:round(x*pow(10,nsf-1-floor(log10(abs(x)))),0)*pow(10,-nsf+1+floor(log10(abs(x))));
 
</pre>
 
</pre>
Line 12: Line 12:
 
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.
 
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="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:30px 0 25px;">
 
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
 
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
  
Line 22: Line 22:
  
 
<div style="margin:20px 0 20px;">
 
<div style="margin:20px 0 20px;">
[http://35.193.77.29/mod/quiz/view.php?id=153<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)''
+
<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;">[http://35.193.77.29/mod/quiz/view.php?id=153 <span style="color:white;">Play it </span>]</span>   [[Formulas_question_type#Examples|Login info]]  ''(Open in new tab: Ctrl+Shift+Click)''
 
</div>
 
</div>
 +
 
</div>
 
</div>
  
<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:20px 0 25px;">
+
<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:35px 0 25px;">
 
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
 
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
  
 
This example is a significant figures drill.
 
This example is a significant figures drill.
  
<pre style="font-size:113%;width: 98%;">
+
<pre style="font-size:113%;width: 97%;">
 
General
 
General
 
   Question name!      Significant figures drill
 
   Question name!      Significant figures drill
Line 37: Line 38:
 
   Random variables    # a    plus or minus sign
 
   Random variables    # a    plus or minus sign
 
                       # b    exponent varying from -4 to 4 in steps of 0.01
 
                       # b    exponent varying from -4 to 4 in steps of 0.01
                       # rnsf  random number of significant figures : 1, 2, 3, or 4
+
                       # rnsf  random number of significant figures: 1, 2, 3, or 4
 
                       a={-1,1};
 
                       a={-1,1};
 
                       b={-4:4.01:0.01};
 
                       b={-4:4.01:0.01};
Line 76: Line 77:
 
             margin: 15px 0 15px;
 
             margin: 15px 0 15px;
 
             ">
 
             ">
It is always a good idea to document your work using comments in the Variable fields.</div>
+
It is always a good idea to document your work using comments in the '''Variables''' fields.</div>
  
 
In this example, values to be rounded range from -10 000 to +10 000. In order to have the same number of values in each order of magnitude, hence a more interesting exercise, the random variable <span style="font-family:monospace;font-size:113%;">b</span> is used as a power of 10. By letting:
 
In this example, values to be rounded range from -10 000 to +10 000. In order to have the same number of values in each order of magnitude, hence a more interesting exercise, the random variable <span style="font-family:monospace;font-size:113%;">b</span> is used as a power of 10. By letting:
Line 93: Line 94:
  
 
<div style="margin:20px 0 20px;">
 
<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)''
+
<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;">[http://35.193.77.29/mod/quiz/view.php?id=152 <span style="color:white;">Play it </span>]</span>   [[Formulas_question_type#Examples|Login info]]  ''(Open in new tab: Ctrl+Shift+Click)''
 
</div>
 
</div>
 +
 
</div>
 
</div>
  
Line 104: Line 106:
 
The value of <span style="vertical-align:3px;"><math>0!</math></span> is <span style="vertical-align:3px;"><math>1</math></span>, according to the convention for an empty product." (Reference: https://en.wikipedia.org/wiki/Factorial).
 
The value of <span style="vertical-align:3px;"><math>0!</math></span> is <span style="vertical-align:3px;"><math>1</math></span>, according to the convention for an empty product." (Reference: https://en.wikipedia.org/wiki/Factorial).
  
The Formulas question calculates the value of <span style="vertical-align:3px;"><math>n!</math></span> up to <span style="vertical-align:3px;"><math>n=170</math></span> (which would correspond to the largest number that can be handled by PHP). For larger values of <span style="vertical-align:1px;"><math>n</math></span>, the Formulas question gives <span style="font-family: monospace;font-size:113%;">INF</span> for the value of <span style="vertical-align:4px;"><math>n!</math></span>.
+
With the built-in function <span style="font-family: monospace;font-size:113%;">fact()</span>, the Formulas question calculates factorial values up to <span style="vertical-align:3px;"><math>170!=7.26\rm{E}306</math></span> (which would correspond to the largest number that can be handled by PHP). For larger values of <span style="vertical-align:1px;"><math>n</math></span>, <span style="font-family: monospace;font-size:113%;">fact()</span> returns <span style="font-family: monospace;font-size:113%;">INF</span> for the value of <span style="vertical-align:4px;"><math>n!</math></span>.
 +
 
 +
However input (with <span style="font-family: monospace;font-size:113%;">{_0}</span>, <span style="font-family: monospace;font-size:113%;">{_1}</span>, etc.) is limited to a maximum value corresponding to <span style="vertical-align:4px;"><math>102!=9.61\rm{E}161</math></span>.<sup>(Explain why)</sup>
 +
 
 +
===References===
 +
 
 +
* Factorials can readily be evaluated up to 170! on Google built-in calculator, under 64-bit Windows and Android:  [https://www.google.ca/search?&q=%3D170! 170!] 
 +
 
 +
* For larger factorials, see WolframAlpha:  [https://www.wolframalpha.com/input/?i=1000! 1000!]  [https://www.wolframalpha.com/input/?i=(10%5E100)! 10<sup>100</sup>!]
 +
 
 +
<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:30px 0 25px;">
 +
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
 +
 
 +
This simple example illustrates the use of the <span style="font-family: monospace;font-size:113%;">fact()</span> function.
 +
 
 +
<pre style="font-size:113%;width: 97%;">
 +
General
 +
  Question name!      Factorial - example 1
 +
Variables
 +
  Random variables    n = {2:8};
 +
                      m = {2:8};
 +
  Global variables    x = fact(n)*fact(m);
 +
Main question
 +
  Question text!      Factorial - example 1
 +
Part 1
 +
  Part's mark*        1
 +
  Answer type          Number
 +
  Answer*              x
 +
  Grading criteria*    Absolute error == 0
 +
  Part's text          Calculate:
 +
                      {n}! x {m}! = {_0} (enter value using integer format)
 +
Combined feedback
 +
  For any correct response
 +
                      The correct answer is: {x}
 +
  For any incorrect response
 +
                      The correct answer is: {x}
 +
</pre>
 +
 
 +
The Formulas question should look like this:
 +
 
 +
[[File:Formulas201801021122.png|680px]]
 +
 
 +
<div style="margin:20px 0 20px;">
 +
<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;">[http://35.193.77.29/mod/quiz/view.php?id=173 <span style="color:white;">Play it </span>]</span>   [[Formulas_question_type#Examples|Login info]]  ''(Open in new tab: Ctrl+Shift+Click)''
 +
</div>
  
However input (with {_0}, {_1}, etc.) is limited to a maximum value of <span style="vertical-align:4px;"><math>102!</math></span>.
+
</div>
  
<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:20px 0 25px;">
+
<div style="border:1px solid #bce8f1;border-radius:4px;padding: 0px 15px 0px; margin:35px 0 25px;">
 
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
 
<div style="font-family:Lucida Sans Unicode;font-size:150%;color:#f98012;margin:10px 0 10px;>Example</div>
  
This example deals with the display of the correct answers with different numbers of significant figures.
+
This slightly more elaborate example shows that the <span style="font-family: monospace;font-size:113%;">fact()</span> function can handle large factorials and also that calculations with factorials can easily be performed using the <span style="font-family: monospace;font-size:113%;">fact()</span> function.
 +
 
 +
<pre style="font-size:113%;width: 97%;">
 +
General
 +
  Question name!      Factorial - example 2
 +
Variables
 +
  Random variables    n = {0:171:1};
 +
                      nn = {12:171:1};
 +
                      na = {1:10};
 +
                      m = {0:103:1};
 +
  Global variables    x=fact(m);
 +
Main question
 +
  Question text!      Factorial - example 2
 +
Part 1
 +
  Part's mark*        1
 +
  Answer type          Number
 +
  Answer*              x
 +
  Grading criteria*    Relative error < 0.01
 +
  Part's text          1. Calculate:
 +
                      {m}! = {_0} (use scientific notation for large numbers)
 +
                      2. It can easily be shown that {nn}! / {=nn-na}! = {=fact(nn)/fact(nn-na)}.
 +
Combined feedback
 +
  For any correct response
 +
                      The correct answer is: {x}
 +
  For any incorrect response
 +
                      The correct answer is: {x}
 +
</pre>
  
 
The Formulas question should look like this:
 
The Formulas question should look like this:
  
[[File:Formulas201712310126.png|680px]]
+
[[File:Formulas201801020347.png|680px]]
  
 
<div style="margin:20px 0 20px;">
 
<div style="margin:20px 0 20px;">
[http://35.193.77.29/mod/quiz/view.php?id=153<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)''
+
<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;">[http://35.193.77.29/mod/quiz/view.php?id=172 <span style="color:white;">Play it </span>]</span>   [[Formulas_question_type#Examples|Login info]]  ''(Open in new tab: Ctrl+Shift+Click)''
 
</div>
 
</div>
 
</div>
 
</div>
 +
  
  
Line 126: Line 199:
  
 
[[Formulas_question_type|← FORMULAS QUESTION TYPE]]
 
[[Formulas_question_type|← FORMULAS QUESTION TYPE]]
 +
 +
===In other languages===
 +
[https://docs.moodle.org/all/es/F%C3%B3rmulas:_M%C3%A1s_ejemplos Español]<br>
 +
[https://docs.moodle.org/3x/fr/Formules:_Plus_d'exemples Français]

Latest revision as of 05:17, 22 January 2018

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 values 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:

Formulas201712310126.png

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

Example

This example is a significant figures drill.

General
  Question name!       Significant figures drill
Variables
  Random variables     # a     plus or minus sign
                       # b     exponent varying from -4 to 4 in steps of 0.01
                       # rnsf  random number of significant figures: 1, 2, 3, or 4
                       a={-1,1};
                       b={-4:4.01:0.01};
                       rnsf={1,2,3,4};
  Global variables     # nx    number x = ± 10^b
                       nx=a*pow(10,b);
                       # Rounding routine:
                       # x     number to round
                       # nsf   number of significant figures
                       # xr    rounded value of x
                       x=nx;
                       nsf=rnsf;
                       xr=x==0?x:round(x*pow(10,nsf-1-floor(log10(abs(x)))),0)*pow(10,-nsf+1+floor(log10(abs(x))));
Main question
  Question text!       Significant figures drill
Part 1
  Part's mark*         1
  Answer type          Number
  Answer*              xr
  Grading criteria*    Relative error < 0.0001
  Part's text          Number to round: {nx}
                       Number of significant digits to keep: {ncs}
                       Rounded number: {_0}
Combined feedback
  For any correct response
                       The correct answer is: {xr} 
  For any incorrect response
                       The correct answer is: {xr} 

In the Variables fields (random, global and local), lines starting with # are treated as comments.

It is always a good idea to document your work using comments in the Variables fields.

In this example, values to be rounded range from -10 000 to +10 000. In order to have the same number of values in each order of magnitude, hence a more interesting exercise, the random variable b is used as a power of 10. By letting:

x = ± 10b

with b ranging from -4 to +4 in steps of 0.01, there are one hundred random values in each order of magnitude (0.000 1 to 0.001, 0.001 to 0.01, 0.01 to 0.1, 0.1 to 1, 1 to 10, 10 to 100, 100 to 1 000 and 1 000 to 10 000), both positive and negative.

In total, this example generates 6 408 different random questions:

2 (a={-1,1}) × 801 (b={-4:4.01:0.01}) × 4 (rnsf={1,2,3,4}) = 6 408

The Formulas question should look like this:

Formulas201712301427.png

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

Factorial

"In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,

5!=5\times4\times3\times2\times1=120.

The value of 0! is 1, according to the convention for an empty product." (Reference: https://en.wikipedia.org/wiki/Factorial).

With the built-in function fact(), the Formulas question calculates factorial values up to 170!=7.26\rm{E}306 (which would correspond to the largest number that can be handled by PHP). For larger values of n, fact() returns INF for the value of n!.

However input (with {_0}, {_1}, etc.) is limited to a maximum value corresponding to 102!=9.61\rm{E}161.(Explain why)

References

  • Factorials can readily be evaluated up to 170! on Google built-in calculator, under 64-bit Windows and Android:  170!
  • For larger factorials, see WolframAlpha:  1000!  10100!
Example

This simple example illustrates the use of the fact() function.

General
  Question name!       Factorial - example 1
Variables
  Random variables     n = {2:8};
                       m = {2:8};
  Global variables     x = fact(n)*fact(m);
Main question
  Question text!       Factorial - example 1
Part 1
  Part's mark*         1
  Answer type          Number
  Answer*              x
  Grading criteria*    Absolute error == 0
  Part's text          Calculate:
                       {n}! x {m}! = {_0} (enter value using integer format)
Combined feedback
  For any correct response
                       The correct answer is: {x} 
  For any incorrect response
                       The correct answer is: {x} 

The Formulas question should look like this:

Formulas201801021122.png

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

Example

This slightly more elaborate example shows that the fact() function can handle large factorials and also that calculations with factorials can easily be performed using the fact() function.

General
  Question name!       Factorial - example 2
Variables
  Random variables     n = {0:171:1};
                       nn = {12:171:1};
                       na = {1:10};
                       m = {0:103:1};
  Global variables     x=fact(m);
Main question
  Question text!       Factorial - example 2
Part 1
  Part's mark*         1
  Answer type          Number
  Answer*              x
  Grading criteria*    Relative error < 0.01
  Part's text          1. Calculate:
                       {m}! = {_0} (use scientific notation for large numbers)
                       2. It can easily be shown that {nn}! / {=nn-na}! = {=fact(nn)/fact(nn-na)}.
Combined feedback
  For any correct response
                       The correct answer is: {x} 
  For any incorrect response
                       The correct answer is: {x} 

The Formulas question should look like this:

Formulas201801020347.png

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


Back to top of page

← FORMULAS QUESTION TYPE

In other languages

Español
Français