0
$\begingroup$

If you look at the first example of FindFormula, why is the result Mathematica produces showing an Abs?

 Table[{x, N[x Sin[x]]}, {x, 0, 4, .3}]

 FindFormula[%, x]

The result on the web page is

$$1. x \sin(x)$$

However, when I run the example on V12.0.0. on Windows 10, it returns the result

$$1. ~abs (x) ~\sin(x)$$

All of the $x$ values are positive, so why is MMA adding the abs to the result?

It is as if MMA is figuring how to go back in time, but that is odd given that that is not the data set.

Update

If I kill my MMA session and run this again, it produces the expected result. However, if I rerun the FindFormula command, the Abs results shows up again and continuously shows that same result after re-entering the data and re-running the command.

$\endgroup$
3
  • $\begingroup$ @BobHanlon: I killed and restarted my MMA session and tried again and now I get the same. If I enter the data again and run the command, I get Abs[x] Sin[x] again. Is this some sort of bug? I updated the question with this tidbit - so thanks for trying that. $\endgroup$
    – Moo
    Nov 7, 2019 at 19:39
  • $\begingroup$ @BobHanlon: I totally get the usefulness of such an option. What I can't understand is why it produces results that are not anticipated or maybe not even desired. $\endgroup$
    – Moo
    Nov 7, 2019 at 21:41
  • 1
    $\begingroup$ FindFormula has no way of knowing what you anticipate or consider desired unless you clarify with its options. As it generates likely formulas, it looks for the best fit within the allowed search time. For your data, {x Sin[x], 1.` x Sin[x], Abs[x] Sin[x], x Sin[Abs[x]]} are all equivalent (i.e., Simplify[Equal @@ {x Sin[x], 1.` x Sin[x], Abs[x] Sin[x], x Sin[Abs[x]]}, x >= 0] evaluates to True) and would provide identical fits. It likely returns the first of these formulas tried which appears to be determined by the random seeding. $\endgroup$
    – Bob Hanlon
    Nov 8, 2019 at 2:06

1 Answer 1

5
$\begingroup$
$Version

(* "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)" *)

data = Table[{x, N[x Sin[x]]}, {x, 0, 4, .3}];

FindFormula does not necessarily give a consistent result. Its algorithms make use of a random seed and as the seed evolves so can the results. For example,

Table[FindFormula[data, x], {10}]

(* {1. x Sin[x], x Sin[x], x Sin[x], x Sin[Abs[x]], x Sin[x], 1. x Sin[x], 
 Abs[x] Sin[x], 1. x Sin[x], x Sin[x], x Sin[x]} *)

Using the same seed for each use will give consistent results.

Table[FindFormula[data, x, RandomSeeding -> 1234], {10}]

(* {x Sin[x], x Sin[x], x Sin[x], x Sin[x], x Sin[x], x Sin[x], x Sin[x], 
 x Sin[x], x Sin[x], x Sin[x]} *)

Other option choices can have similar results

Table[FindFormula[data, x, PerformanceGoal -> "Quality", 
  SpecificityGoal -> 1], {10}]

(* {x Sin[x], x Sin[x], x Sin[x], x Sin[x], x Sin[x], x Sin[x], x Sin[x], 
 x Sin[x], x Sin[x], x Sin[x]} *)
$\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.