I would like to create the following function:
It should approximate a function func[x]
by piecewise polynomial interpolations, splitting the approximate function in n
different polynomials, from xMin
to xMax
.
autoPiecewiseApproximation[func[x],{xMin,xMax,n}]
Example: the square root function
For instance for two subdivisons n = 2
and xMin = 0
, xMax = 1
, the function would automatically generate this:
m = Piecewise[{{Fit[
Table[{x, Sqrt[x]}, {x, 0, 0.5, .01}], {1, x, x^2, E^x}, x] ,
0 <= x <= 0.5}, {Fit[
Table[{x, Sqrt[x]}, {x, 0.5, 1, .01}], {1, x, x^2, E^x}, x] ,
0.5 < x <= 1}}]
Anyone knows how to do this correctly ?