1

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

$$f[m,M,k,v,w]$$

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];
xyz
  • 605
  • 4
  • 38
  • 117
user1581390
  • 231
  • 1
  • 5

1 Answers1

1

I managed to interpolate it using:

f = 
 FunctionInterpolation[
  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:

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

enter image description here

xyz
  • 605
  • 4
  • 38
  • 117
user1581390
  • 231
  • 1
  • 5