I am trying to interpolate a function of $5$ variables


by creating a 5D table of $n$ values in each dimension.

For[im = mbegin, im <= mend, im += (mend - mbegin)/n,
 For[iM = Mbegin, iM <= Mend, iM += (Mend - Mbegin)/n,
   For[iv = vbegin, iv <= vend, iv += (vend - vbegin)/n,
    For[iw = wbegin, iw <= wend, iw += (wend - wbegin)/n,
     For[ix = xbegin, ix <= xend, ix += (xend - xbegin)/n,
      Module[{ik = g[im,ix], val},
         val = f[im, iM, ik, iv, iw];
         AppendTo[vals, val]; 

         AppendTo[keysm, im];
         AppendTo[keysM, iM];
         AppendTo[keysv, iv];
         AppendTo[keysw, iw];
         AppendTo[keysx, ix];

No idea how to use that next.

I have tried using Interpolation, but even with $3$ dimensions it fails:

data = Flatten[
 Table[{nm, nM, nv, f[nm, nM, kbegin, nv, wbegin]}, {nm, mbegin, 
  mend, (mend - mbegin)/count}, {nM, Mbegin, 
  Mend, (Mend - Mbegin)/count}, {nv, vbegin, 
  vend, (vend - vbegin)/count}], 1];
f = Interpolation[data];
  • $\begingroup$ related: mathematica.stackexchange.com/questions/14157/… $\endgroup$ Commented May 31, 2015 at 21:47
  • $\begingroup$ Okay I now got a result using FunctionInterpolation, will report back. $\endgroup$ Commented May 31, 2015 at 21:58
  • $\begingroup$ This answer contains important considerations on the practical use of FunctionInterpolation and comparison with other function interpolation methods. $\endgroup$ Commented Jul 1, 2015 at 11:28

1 Answer 1


I managed to interpolate it using:

f = 
  g[m, M, k, v, w], 
  {m, mbegin,mend}, {M, Mbegin, Mend}, 
  {k, kbegin, kend}, {v, vbegin,vend}, {w, wbegin, wend}];

It's not perfect though. Here is a plot of $f$ versus the original function $g$, for the variable m and the others constant:

  {f[m, Mbegin, kbegin, vbegin, wbegin], 
   g[m, Mbegin, kbegin, vbegin, wbegin]}, {m, mbegin, mend},
   PlotRange -> Full, PlotLegends -> "Expressions"]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.