FindFormula[data]
finds a pure function that approximates data.
FindFormula[data,x]
finds a symbolic function of the variable x that approximates data.
FindFormula[data,x,n]
finds up to n functions that approximate data.
FindFormula[data,x,n,prop]
returns up to n best functions associated with property prop.
FindFormula[data,x,n,{prop1,prop2,…}]
returns up to n best functions associated with properties prop1, prop2, etc.
FindFormula
FindFormula[data]
finds a pure function that approximates data.
FindFormula[data,x]
finds a symbolic function of the variable x that approximates data.
FindFormula[data,x,n]
finds up to n functions that approximate data.
FindFormula[data,x,n,prop]
returns up to n best functions associated with property prop.
FindFormula[data,x,n,{prop1,prop2,…}]
returns up to n best functions associated with properties prop1, prop2, etc.
Details and Options
- The data should be either an array of the form {{x1,y1},{x2,y2},…} or {y1,y2,…}, or a TimeSeries object.
- Data of the form {y1,y2,…} is equivalent to data of the form {{1,y1},{2,y2},…}.
- FindFormula[data,x,n,All] creates a Dataset object with all possible properties.
- Properties supported include:
-
"Score" internal score "Complexity" complexity of the function "Error" mean squared error All all the previous properties - The following options can be given:
-
PerformanceGoal Automatic aspect of performance to optimize RandomSeeding Automatic what seeding of pseudorandom generators should be done internally SpecificityGoal 1 what formula complexity to seek TargetFunctions All functions to consider TimeConstraint Automatic maximum time to be spent in finding the result - Possible settings for PerformanceGoal include:
-
"Speed" minimize the time spent in finding the result "Quality" try to find better results - Possible settings for SpecificityGoal include:
-
"Low" for simpler fits "High" for more complex functions s specificity between 0 (lowest) and Infinity (highest) - FindFormula[data,x,SpecificityGoal->Infinity] finds solutions that minimize the error.
- SpecificityGoal equal to 1 gives the best predictive performance.
- Possible settings for TargetFunctions include:
-
All all functions listed below {
,
,…}functions 
- Possible functions for TargetFunctions are Plus, Times, Power, Sin, Cos, Tan, Cot, Log, Sqrt, Csc, Sec, Abs, and Exp.
- Possible settings for TimeConstraint include:
-
Automatic automatic t maximum t seconds - Possible settings for RandomSeeding include:
-
Automatic automatically reseed every time the function is called Inherited use externally seeded random numbers seed use an explicit integer or strings as a seed
Examples
open all close allBasic Examples (2)
Make a table of values of the function x Sin[x]:
Table[{x, N[x Sin[x]]}, {x, 0, 4, .3}]FindFormula finds a formula that generates the data:
FindFormula[%, x]Plot the exponents of known Mersenne primes:
plot = ListLogPlot[mersenneexponents = MersennePrimeExponent[Range[48]]]Find the best simple function describing the data:
formula = FindFormula[Log[mersenneexponents], TargetFunctions -> {Power, Times}, SpecificityGoal -> "Low"]Visualize the fitted functions with the data:
Show[plot, LogPlot[Exp[formula[n]], {n, 1, 48}]]Scope (3)
Generate data with normally distributed noise:
data = Table[{x, Sin[2x] + Cos[x] + RandomVariate[NormalDistribution[0, 0.2]]}, {x, RandomReal[{-10, 10}, 1000]}];ListPlot[data]Find the first 5 best functions that approximate data:
fits = FindFormula[data, x, 5]Visualize the fitted functions with the data:
Show[ListPlot[data], Plot[fits, {x, -20, 60}, PlotRange -> All]]Generate data with normally distributed noise:
data = Table[{x, -x + 2Sin[x] + RandomVariate[NormalDistribution[0, 0.2]]}, {x, RandomReal[{-10, 10}, 100]}];ListPlot[data]Visualize the dataset for the first 5 functions that approximate data:
fit = FindFormula[data, x, 5, All]Generate data with normally distributed noise:
data = Table[{x, Sin[2x] + x Exp[Cos[x]] + RandomVariate[NormalDistribution[0, 0.2]]}, {x, RandomReal[{-10, 10}, 500]}];ListPlot[data]Look at the first 300 fits and plot their score as functions of the errors and complexity for different settings of SpecificityGoal:
fit = FindFormula[data, x, 300, {"Complexity", "Error", "Score"}, TimeConstraint -> 20, PerformanceGoal -> "Quality", SpecificityGoal -> 1];errorcomplexity = fit[[All, 2]];
errorcomplexity = Select[errorcomplexity, #[[2]] < 20&];
ListPlot3D[errorcomplexity, Filling -> Bottom]fit2 = FindFormula[data, x, 300, {"Complexity", "Error", "Score"}, TimeConstraint -> 20, PerformanceGoal -> "Quality", SpecificityGoal -> Infinity];errorcomplexity = fit2[[All, 2]];
errorcomplexity = Select[errorcomplexity, #[[2]] < 200&];
ListPlot3D[errorcomplexity, Filling -> Bottom]Visualize the first fitted function with the data:
Show[ListPlot[data], Plot[fit[[1, 1]], {x, 0, 20}]]Options (4)
PerformanceGoal (1)
Generate data with normally distributed noise:
data = Table[{x, x Cos[2 x] + Sin[2 x] + x + RandomVariate[NormalDistribution[0, 0.2]]}, {x, RandomReal[{-3, 20}, 1000]}];ListPlot[data]Find the best function that approximates data with its internal score:
fit = FindFormula[data, x, 1, "Score" ]Find the best function that approximates data using PerformanceGoal with its internal score:
fit2 = FindFormula[data, x, 1, "Score", PerformanceGoal -> "Quality" ]Visualize the fitted functions with the data:
Show[ListPlot[data], Plot[{First@fit, First@fit2}, {x, -20, 60}, PlotRange -> All]]RandomSeeding (1)
Generate data with normally distributed noise:
data = Table[{x, Sin[2 + x] + RandomVariate[NormalDistribution[0, 0.2]]}, {x, RandomReal[{-10, 10}, 500]}];Compare different evaluations of FindFormula and notice how they differ:
Table[FindFormula[data, x], 3]Use the option RandomSeeding to avoid having different results:
Table[FindFormula[data, x, RandomSeeding -> 1], 3]SpecificityGoal (1)
Generate data with normally distributed noise:
data = Table[{x, x + RandomVariate[NormalDistribution[0, 2]]}, {x, RandomReal[{-3, 20}, 15]}];ListPlot[data]Find the best functions that approximate data with their errors using different values of SpecificityGoal:
fits = Table[FindFormula[data, x, 1, "Error", SpecificityGoal -> i], {i, {"Low", "High"}}]Visualize the fitted functions with the data:
Table[Show[ListPlot[data], Plot[fits[[i, 1]], {x, -20, 60}, PlotRange -> All]], {i, 1, 2}]TargetFunctions (1)
Generate data with normally distributed noise:
data = Table[{x, x + Log[2 x] + RandomVariate[NormalDistribution[0, 0.2]]}, {x, RandomReal[{0.1, 20}, 1000]}];ListPlot[data]Find the best function that approximates data:
fit = FindFormula[data, x]Find the best function that approximates data using TargetFunctions:
fit2 = FindFormula[data, x, TargetFunctions -> {Times, Log, Plus}]Visualize the fitted functions with the data:
Show[ListPlot[data], Plot[{fit, fit2}, {x, -3, 20}]]Applications (4)
Population Growth (1)
data = Entity["Country", "Poland"][EntityProperty["Country", "Population", {"Date" -> Interval[{DateObject[{1950}], DateObject[{2015}]}]}]]Find the best function that describes data:
fit = FindFormula[data, x]Visualize the fitted function with the data:
Show[DateListPlot[data["Path"], ...], Plot[fit, {x, AbsoluteTime@data["FirstTime"], AbsoluteTime@data["LastTime"]}]]Model Prime Numbers (1)
Find a fit for the first 100 prime numbers:
primes = Table[Prime[n], {n, 100}];fit = FindFormula[primes, x]Compare the fit with the data and with the next 200 primes:
primesNext = Table[Prime[n], {n, 100, 300}];Show[ListPlot[primes], ListPlot[Transpose[{Range[100, 300], primesNext}], PlotStyle -> Red], Plot[fit, {x, 0, 300}, PlotStyle -> Gray], PlotRange -> All]Differential Equation (1)
Find a fit for the numerical solution of a differential equation:
sol = First[y /. NDSolve[{y'[x] == y[x]Cos[x], y[0] == 1}, y, {x, -5, 300}]];
times = N[Range[-5, 600] / 9];
data = Transpose[{times, sol[times] + RandomReal[.005, Length[times]]}];
lp = ListPlot[data, PlotRange -> All]fit = FindFormula[data, x, 1, TargetFunctions -> {Exp, Sin, Cos}, RandomSeeding -> 1234]Compare the fit with the data:
Show[ListPlot[data], Plot[fit, {x, -20, 90}, PlotRange -> All]]Orbital Mechanics (1)
Plot the orbital periods of planets vs. their semimajor axes:
data = EntityValue["Planet", {"SemimajorAxis", "OrbitPeriod"}];ListPlot[Thread[Callout[data, EntityList["Planet"]]]]Find the best simple function describing the orbital radius in terms of the orbital period:
formula = FindFormula[data, a, RandomSeeding -> 1234]Find the constant of proportionality:
formula /. a -> Quantity[1, "AstronomicalUnit"]Compare with the exact formula given by Kepler's third law:
kepler = FormulaData[{"KeplersThirdLaw", "Sun"}]The exact constant of proportionality has value:
Sqrt@UnitConvert[kepler[[2]] / QuantityVariable["a", "Length"] ^ 3, ("Days"^2/"AstronomicalUnit"^3)]Compare with the different values from the orbital data directly:
Sqrt@UnitConvert[(#2^2/#^3)&@@@data, ("Days"^2/"AstronomicalUnit"^3)]Text
Wolfram Research (2015), FindFormula, Wolfram Language function, https://reference.wolfram.com/language/ref/FindFormula.html (updated 2017).
CMS
Wolfram Language. 2015. "FindFormula." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/FindFormula.html.
APA
Wolfram Language. (2015). FindFormula. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FindFormula.html
BibTeX
@misc{reference.wolfram_2026_findformula, author="Wolfram Research", title="{FindFormula}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/FindFormula.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_findformula, organization={Wolfram Research}, title={FindFormula}, year={2017}, url={https://reference.wolfram.com/language/ref/FindFormula.html}, note=[Accessed: 13-June-2026]}