Suppose I have a function f[x,y,z,w] and all the variables are constrained in the region [-1,1]. Now, I want to plot this function in 1d with the y-axis being f[x,y,z,w] and the x-axis being x. To get this plot, I require the the rest three variables y,z,w to vary freely, so in the end, the plot I get will be a region instead of a curve due to the free-varying y,z,w. This region will provide an overall sight on constraints of f[x,y,z,w] viewed along the x-axix. While in some cases one can do this by deriving the minimal/maximal conditions for f[x,y,z,w], this will not work if the function gets too complicated for one to obtain these conditions analytically. With that, is there any way to achieve what I want to do here? To be specific, let us just assume f[x,y,z,w] = Abs[x y z w].



1 Answer 1


Well, if the function is too complicated to be treated analytically, then you must do it numerically.

To sample values from f you should know something about how fast it changes, how large the gradient is at different places. For the simplest case, you may assume an equidistant grid. In case of your oversimplified example, it is not even necessary to sample all y,z,w, values, all depends on he function at hand.

Let us assume that it is necessary to sample all y,w,z values. For an example we choose a grid with a spacing of 0.1. Then we get following Min/Max intervals for different x:

f[x_,y_,z_,w_]= Abs[x y z w];    
dat = Table[
      {x, #} & /@ 
         f[x, y, z, w], {y, -1, 1, 0.1}, {z, -1, 1, 0.1}, {w, -1, 1, 0.1}]]
      , {x, -1, 1, 0.1}]

Finally we may plot the intervals

Graphics[{Red, Line /@ dat}]

enter image description here

  • $\begingroup$ Thanks Daniel, you are the hero of my day $\endgroup$
    – Y.Du
    May 18, 2023 at 0:05

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.