1
$\begingroup$

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];
$\endgroup$
1
$\begingroup$

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

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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