# Curve fitting an equation to remove irrationals

Suppose I have a long equation with square roots and various trigonometric functions. Is there a way to approximate this function (over a fixed range) by curve fitting? My reading is that curve fitting is often used to regress over data points. In this case, the input would be a function though. Are there ways to force curve fitting use "simpler" integer functions? For instance, disallow the use of square roots or other irrational functions.

Any thought appreciated

• You can calculate values of your function on an appropriate grid, then feed those to e.g. NonlinearModelFit. You will have to provide a model function to fit those points to, so you have full freedom to choose which functions appear in your model. Dec 19, 2016 at 7:23
• Dec 19, 2016 at 8:20
• Use FunctionInterpolation to get a piecewise polynomial interpolation. Dec 19, 2016 at 8:48
• @Szabolcs I've just tried FunctionInterpolation, but how do I obtain the equation for the InterpolatingFunction object? Dec 19, 2016 at 9:48

I am not very familiar with this area, but I think you may be looking for the FunctionApproximations package, or maybe PadeApproximant.

For example, let us approximate the function

f[x_] := Cos[x] + Sqrt[x]


with rational expressions on the interval $[0,2]$.

approx = EconomizedRationalApproximation[f[x], {x, {0, 2}, 2, 2}];
Plot[{f[x], approx} // Evaluate, {x, 0, 2}]


There are several other approximation methods in the package.

You may want to numericize the result using N[approx] // Simplify, as the exact coefficients are complicated.