Tag Info

New answers tagged

2

In general, I'd also use Piecewise because it's clearest. However, to play devil's advocate, here is an example of where Piecewise is not the best choice (at least in Mathematica version 10.0.0): Plot[ Piecewise[{{Sin[x], {x, 0} ∈ ImplicitRegion[-1 < x < 1, {x, y}]}, {1, True}}], {x, -2, 2}] The warning here seems to be due to the fact ...


0

Option 1 : Condition f[a_,b_]/;a>b := Sin[a-b]; f[a_,b_]/;a<b := Tan[a/b]; f[a_,b_]/;a==b := Cos[a+b]; Option 2 : Piecewise f[a_,b_] := Piecewise[{ {Sin[a-b], a>b}, {Tan[a/b], a<b}, {Cos[a+b], a==b} }] Option 3 : Which Which[ a>b,Sin[a-b], a<b,Tan[a/b] a==b,Cos[a+b] ] Option 4 : If If[a>b, Sin[a-b], ...


4

From testing in version 7, which I have not yet repeated in version 10, I recommend that you use your first form, as I found it to have at least a small performance advantage over Piecewise etc. I also find it very readable. If you can reformulate your function for application to vectors then the use of UnitStep etc., where possible without being overly ...



Top 50 recent answers are included