0
votes

I'm trying to define a bivariate function that takes values depending on whether a condition is met. I make them work for univariate case but I'm stuck with the bivariate case:

g[x_, y_] := 10 /; x < 10
g[x_, y_] := 20 /; (x >= 10 && y < 5)
g[x_, y_] := -5 /; (x >= 10 && y >= 5);

This function never gives me the value of -5.

g[12,10] = 20?

1
Your definition works fine and Mark's answer is no different from yours. You probably had a previous definition for g and clearing it helped. - abcd
Yes indeed, OP's definition of g works fine. Now. Strange thing is that when I tried it in a fresh Mathematica session last night the definitions returned $Failed. - High Performance Mark

1 Answers

2
votes

This works for me:

Clear[g]
g[x_, y_] /; x < 10 := 10
g[x_, y_] /; x >= 10 \[And] y < 5 := 20
g[x_, y_] /; x >= 10 \[And] y >= 5 := -5

then

In[73]:= g[12, 10]

Out[73]= -5

Why this version works and your version doesn't I'm not sure. Perhaps someone else will come along and tell us