4
$\begingroup$

I have a scalar function (actually, a set of eigenvalues) which takes two parameters, say $f(x,y)$. I would like to make a 2D plot of this function for a continuous, closed loop of parameter values in the shape of a square, which would consist of four line segments connecting the four corners as $$(x(t),y(t)) = (0,0)\rightarrow(1,0)\rightarrow(1,1)\rightarrow(0,1)\rightarrow(0,0)$$ You can equivalently think of making a 3D plot of this function and tracing its value along a closed contour of parameters and plotting only this "cross section" of the function. I'm not sure how this can be implemented in Mathematica.

$\endgroup$
1
  • $\begingroup$ Why not use Plot3D? $\endgroup$
    – cvgmt
    Jun 18 at 23:44

2 Answers 2

5
$\begingroup$

Define a function you want to plot

f[x_, y_] := Cos[x] + Sin[y]

Interpolate over the path

p = Interpolation[{{0, {0, 0}}, {1, {0, 1}}, {2, {1, 1}}, {3, {1, 
     0}}, {4, {0, 0}}}, InterpolationOrder -> 1]

Plot

Plot[f @@ p[t], {t, 0, 4}]

enter image description here

Improved plot

pts = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
dts = Norm /@ Differences[pts];
adts = Join[{0}, Accumulate[dts]];
path = Transpose[{adts, pts}];
p = Interpolation[path, InterpolationOrder -> 1];
Plot[f @@ p[t], {t, 0, 4}, 
 FrameTicks -> {{Automatic, None}, {path, None}}, 
 GridLines -> {Accumulate[dts], None}, 
 PlotTheme -> {"Monochrome", "Frame"}]

enter image description here

$\endgroup$
6
$\begingroup$
  • 3D
f[x_, y_] = 5 x*Sin[3 x*y] + Cos[8 x] + 2 + Sin[10 y];
Plot3D[f[x, y], {x, 0, 1}, {y, 0, 1}, BoundaryStyle -> {Thick, Red}, 
 PlotStyle -> None, Mesh -> None, ViewProjection -> "Orthographic"]

enter image description here

  • 2D
f[x_, y_] = 5 x*Sin[3 x*y] + Cos[8 x] + 2 + Sin[10 y];
pts = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
lines = Partition[pts, 2, 1, 1];
plots = Table[
   Plot[f @@ ((1 - t)*line[[1]] + t*line[[2]]), {t, 0, 1}], {line, 
    lines}];
GraphicsGrid[Partition[plots, 2, 2]]

enter image description here

$\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.