Skip to main content
1 of 4
james
  • 3.1k
  • 14
  • 30

Automatic Picewise Approximation

I would like to create the following function: It should approximate a function func[x] by piece-wise polynomial interpolations, splitting the approximate function in N different polynoms, 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 ?

james
  • 3.1k
  • 14
  • 30