Eval()vs.substitute()

From WeBWorK_wiki
Revision as of 10:13, 17 June 2008 by Nbennett (talk | contribs) (New page: The aim of this page is to demonstrate the difference between <code> eval() </code> and <code> substitute </code>. Note:PGLabs is an efficient way to check code. $f = Compute(sqrt(3...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The aim of this page is to demonstrate the difference between eval() and substitute .

Note:PGLabs is an efficient way to check code.

$f = Compute(sqrt(3x + 1);
$fx = $f->eval(x=>"3");
displays 3.16228

The correct answer is a number.

$f = Compute(sqrt(3x + 1);
$fx = $f->eval(x=>"3");
displays (3.16228)

The correct answer is a formula (hence the parenthesis)

One of the biggest differences between eval() and substitute is when they are used in conjunction with flags such as reduceConstants and reduceConstantFunctions , which is described in more detail at:FormattingCorrectAnswers