0

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?

2
  • 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. Commented Jan 29, 2013 at 2:07
  • 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. Commented Jan 29, 2013 at 6:54

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Mark. Works perfecly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.