3
$\begingroup$

Is there any command in Mathematica to plot an expression: $f(x,y)=\exp^{x\pm y}$. As far as I know, it is not possible as the expression will vary differently with the sign. I have seen such plots in some of the research articles without mentioning that they have been plotted for a single sign, so I want to know if there is any possibility.

$\endgroup$
2
  • 3
    $\begingroup$ Is there a reason why you can't do Plot3D[{Exp[x+y],Exp[x-y]},{x,-2,2},{y,-2,2},PlotRange->All] ? Note that PlusMinus[x,y] is for display only and will not generate the same plot. i.e. Plot3D[Exp[PlusMinus[x,y]],{x,-2,2},{y,-2,2},PlotRange->All] will not work $\endgroup$
    – Nasser
    Commented Apr 28 at 5:03
  • $\begingroup$ @Nasser Thank you $\endgroup$
    – Rag
    Commented May 1 at 8:22

2 Answers 2

8
$\begingroup$

Define: ( because I can )

rule = {{PlusMinus :> Plus}, {PlusMinus :> Subtract}};

Plot3D[Evaluate[Exp[x ± y] /. rule]
 , {x, -2, 2}, {y, -2, 2}
 , PlotRange -> All
 , PlotStyle -> {Red, Cyan}
 , Exclusions -> None
 , PlotLegends -> "Expressions"
 ]

enter image description here


Another experiment, perhaps to show envelopes:

Plot3D[Evaluate@{Exp[x ± y] /. rule // MinMax}
 , {x, -2, 2}, {y, -2, 2}
 , PlotRange -> All
 , PlotStyle -> {White, Orange}
 , Exclusions -> None
 , PlotLegends -> "Expressions"
 ]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ To handle expressions with mixed $\pm$ and $\mp$, such as $\exp (x\pm y)(1\mp x) $, just extend the rule to rule = {{PlusMinus :> Plus, MinusPlus :> Subtract}, {PlusMinus :> Subtract, MinusPlus :> Plus}}. $\endgroup$
    – Domen
    Commented Apr 29 at 13:33
4
$\begingroup$

If it won't interfere with the rest of your work, you can define

PlusMinus[a_, b_] := {a + b, a - b}

and then

f[x_, y_] := Exp[x \[PlusMinus] y]
f[a, b] (* {E^(a+b),E^(a-b)} *)

Plot3D[
    Evaluate@f[x, y],
    {x, -2, 2}, {y, -2, 2}, PlotRange -> All, 
    PlotStyle -> {Red, Cyan}, Exclusions -> None, 
    PlotLegends -> "Expressions"
]

Produces a plot like in @Syed's answer.

$\endgroup$
1
  • 1
    $\begingroup$ Sometimes people write expressions like (a±b) (c±d) where the ±s are correlated with one another, both + or both – but not mixed. Both @Syed's rule and this trick implements the correlation correctly. If you need independent ±s (in this simple example, 4 results) something else is needed. $\endgroup$
    – evanb
    Commented Apr 28 at 13:42

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.