Brute force? I'm pretty sure that's how the fancy calculators do it.
PHP Code:
function solveForX($equation, $answer, $min = null, $max = null)
{
$min = ($min == null) ? -mt_getrandmax() : $min;
$max = ($max == null) ? mt_getrandmax() : $max;
$last['guess'] = null;
while (true)
{
eval('$attempt = ' . str_replace('x', ($guess = mt_rand($min, $max)), $equation) . ';');
if ($attempt == $answer)
{
return($guess);
}
if ($last['guess'] != null)
{
$diff = abs($answer - $attempt);
if ($diff > $last['diff'])
{
if ($guess > $last['guess'])
{
$max = $guess - 1;
}
else
{
$min = $guess + 1;
}
}
}
$last['guess'] = $guess;
$last['diff'] = abs($answer - $attempt);
}
}
echo solveForX('x+(x*.1)', 110);
Note this is oversimplified and will fall into infinite loops on discontinuous functions and functions with noninteger answers. The latter problem is pretty easily resolvable, the former maybe not so much.
Also, it'd probably be neater if it was refactored to use recursion, another exercise I'll leave to the reader.