Difference between revisions of "Eval()vs.substitute()"
Jump to navigation
Jump to search
m (Changed 2nd "eval" to "substitute") |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | The aim of this page is to demonstrate the difference between <code> |
+ | 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. |
Note:[[PGLabs]] is an efficient way to check code. |
||
Line 10: | Line 10: | ||
$f = Compute(sqrt(3x + 1); |
$f = Compute(sqrt(3x + 1); |
||
− | $fx = $f-> |
+ | $fx = $f->substitute(x=>"3"); |
displays (3.16228) |
displays (3.16228) |
||
The correct answer is a formula (hence the parenthesis) |
The correct answer is a formula (hence the parenthesis) |
||
− | One of the biggest differences between <code> |
+ | One of the biggest differences between <code>eval()</code> and <code>substitute</code> is when they are used in conjunction with flags such as <code>reduceConstants</code> and <code>reduceConstantFunctions</code>, which is described in more detail at:[[FormattingCorrectAnswers:_NumbersAndFormulas]] |
Revision as of 17:29, 7 July 2011
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->substitute(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:_NumbersAndFormulas