Reputation: 63
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?
Upvotes: 0
Views: 2480
Reputation: 78344
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
Upvotes: 2