Gnuplot: Conditional splot of a function

691 views Asked by At

I want to splot the function exp(-(x²+y²)) alone and under the constraint of x+y-1=0. The result should be the surface alone as well as a line with a maximum at x=y=0.5. Or in other words, it's the intersection of the function with a (110)-plane.

What I came up so far is something like

f(x,y)=exp(-(x**2+y**2))
g(x,y)=( (x+y-1==0)? f(x,y) : (1/0) )
splot f(x,y), g(x,y)

with and without with lines for g(x,y), but I could not get g(x,y) being displayed - I only see f(x,y). Additionally, I get the very informative error messages:

Error: Key "<META>" added to modifier map for multiple modifiers; Using Mod4, ignoring Mod1

Error: Symbol "Meta_L" added to modifier map for multiple modifiers; Using Mod4, ignoring Mod1

Any ideas?

1

There are 1 answers

0
Miguel On BEST ANSWER

This is not a 3-dimensional plot because you only have one independent variable. The value of y is fixed by x+y-1=0. Therefore, you have to plot f(x,y)=exp(-(x**2+y**2)) evaluated at f(x,1-x):

f(x,y)=exp(-(x**2+y**2))
plot f(x,1-x) w l

enter image description here

Now, of course the above graph is the projection of your curve onto the XZ plane. If you want the 3-dimensional view, then I would recommend a numerical evaluation of the function using the special file name "+":

f(x,y)=exp(-(x**2+y**2))
set xrange [-10:10]
set yrange [-10:10]
splot "++" u ($1):(1.-$1):(f($1,1.-$1)) w l

enter image description here

You can visualize the intersection with your surface:

set isosamples 50
splot f(x,y), "++" u ($1):(1.-$1):(f($1,1.-$1)) w l

enter image description here