5
$\begingroup$

I have this function:

fun = (# - 5.0)^2.0 &

Then, I want to find the minimum:

 FindMinimum[fun[x], x, WorkingPrecision -> 30]

It return:

 FindMinimum::precw: The precision of the argument function ((-5.+x)^2.) is less than WorkingPrecision (30.`). >>
{0, {x -> 5.00000000000000000000000000000}}

How can I get rid of the error? I do not want to use Integers in this function. usage of $MinPrecision = 30; did not help.

$\endgroup$
6
$\begingroup$

I assume that the error arises because 5.0 is only precise to one decimal place...or rather to $MachinePrecision. You can try the following:

fun = SetPrecision[(# - 5.0)^2.0 &, 30];
FindMinimum[fun[x], x, WorkingPrecision -> 30]

which returns (with no error):

{0, {x -> 5.00000000000000000000000000000}}

Indeed, try:

Precision[(# - 5.0)^2.0 &]
(* MachinePrecision *)

Precision[SetPrecision[(# - 5.0)^2.0 &, 30]]
(* 30. *)

My answer is based on this bit of the docs: http://reference.wolfram.com/language/ref/SetPrecision.html

Here's a good tutorial on arbitrary precision in Mathematica: http://reference.wolfram.com/language/tutorial/ArbitraryPrecisionNumbers.html

|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.