I am rather new to Mathematica and I tried to find a solution for my Problem on my own, also looking through this site and the suggested Similar Questions, but I at least could not make out that my Question has been addressed yet. Perhaps it is too basic.

I have a Code where I need to do a few Interpolations and this I do for the same Variables and Boundaries for the Variables. However to test some things I need to change these Variables in the same way in every Interpolation. This is nothing dramatic of course, but I was wondering if there is a neat way to do it.

All Interpolations look as follows

int =
   Table[{#1, #2, #3, 
       F}, {x, -#4, #4}, {y, -#4, #4}, {z, -#4, 4}] & @@ {x, y, 
     z, 5}, 2], InterpolationOrder -> 4]

So now when I want to get the results for different variables I will change x to x/2 etc. in each Interpolation.

Perhaps someone could even tell me how to Parallelize this Question, though the Interpolation is quick anyhow.

Thank you in advance!


I am abbreviating my code here, but trying to give a working example (can't test it at the moment) while making more explicit what I am thinking of.

I am solving a PDE numerically, this is necessary for my work. Afterwards I interpolate the Solution to get NIntegrate to take it properly and not give me an error of evaluating to non-numerical values. Since in my Integration I am not actually using the interpolated solution, but Derivatives of it I interpolatedthe Derivative again and give that to the NIntegrate.


sol= u /. First[ 
{D[u[x,t], {t,2}] - D[u[x,t],{x,2}] - k (u[x,t])^3 == 0 , 
u[-l,t]==u[l,t]}, u, {t,0,Tf}, {x,-l,l}, 
Method->{"MethodOfLines", "SpatialDiscretization"->{"TensorProductGrid","DifferenceOrder"->"Pseudospectral"}}]]

intSol= Interpolation[
Table[{#1,t, sol[x,t]},{x,-#2,#2},{t,0,Tf}]&@@{x,5}, 3], InterpolationOrder->4]

derInt=(D[intSol[#1,Tf],x]-0.5*intSol[#1,Tf]^2+ 0.25*k*intSol[#1,Tf]^4) &@@{x,5};

intDeriv =
Flatten[ Table[{#1,derInt},{x,-#2,#2}] &@@{x,5}, 2],InterpolationOrder->4];

integration=NIntegrate[intDeriv[x], {x,-l,l}, Method->"AdaptiveMonteCarlo"];

There is more, but it is completely decoupled from my question.

In the next step, after the Notebook has evaluated, I would now change the {x,5} to {x/2,10} and have the notebook evaluate again. Since I would have to change that a number of times for each iteration, I was wondering if there was a possibility to just having to change it once and give that to all the Interpolations.

  • 2
    $\begingroup$ Can you show us code that demonstrates how you use your interpolation code? I don’t understand what you are trying to do. Also, if the interpolation works and it is fast, then what exactly is the problem? What qualifies as a “neater” way is likely opinion-based. $\endgroup$
    – MarcoB
    Dec 16 '20 at 14:48
  • $\begingroup$ I'm using the Interpolation afterwards in NIntegrate. I was hoping to get something like interpolation1=...[#1,#2,#3], interpolation2=...[#1,#2,#3] /@@ {variables} If that makes any sense to you. As in I only want to have to write the changes variables once and not copy/past it like 8 times. I hope my reply makes any sense and of course there isn't really a problem. $\endgroup$
    – n00bBoi1
    Dec 16 '20 at 14:58
  • 2
    $\begingroup$ Please show a complete command. Don't use ellipses, show everything, include values for variables. It is crucial that we can RUN your code in order to be able to help you. $\endgroup$
    – MarcoB
    Dec 16 '20 at 16:52
  • $\begingroup$ I editted my Question to hopefully have clarified it. Thank you for your time so far. $\endgroup$
    – n00bBoi1
    Dec 17 '20 at 8:57

Your Answer

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

Browse other questions tagged or ask your own question.