Skip to main content
3 of 4
added 3 characters in body
kglr
  • 400.5k
  • 18
  • 488
  • 929

Automatic Piecewise Approximation

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 ?

james
  • 3.1k
  • 14
  • 30