Student Support Forum: 'functions with conditions' topicStudent Support Forum > General > "functions with conditions"

 Next Comment > Help | Reply To Topic
 Author Comment/Response Andrew DuBuisson 10/21/04 2:09pm I am having trouble using conditions with functions. If this has been answered before, please just refer me. I'll do the work, I just haven't found an answer yet. The text below is all in the notebook too. ---------------- This is an example notebook. In my actual notebook, z is a huge function that I would not like to type in. Independent varables: y, and x of form {x1,x2} Arbitrary funciton: z, its the part of the problem Arbitrary function: func[{y_,x_}] I define an arbitrary value z: z = x[[1]]^2; I understand and accept the warning messages regarding the depth of x. I use immeadiate assignment because I do not want the delayed assignment. Here's an arbitrary function that uses a condition. Notice arbitrary variable z in the third line. In[20]:= Clear[func] func[{y_, x_}] := Evaluate[x + y] /; x[[1]] > y func[{y_, x_}] := Evaluate[x + 4] /; x[[1]] < z func[{2, {3, 4}}] func[{9, {0, 8}}] func[{-9, {-9, 7}}] Out[23]={5,6} Out[24]=func[{9,{0,8}}] Out[25]=func[{-9,{-9,7}}] Unfortunately the condition doesn't work with the variable z in there. I checked to see if it would work with the value of z instead of z itself. In[32]:= Clear[func] func[{y_,x_}]:=Evaluate[x+y]/;x[[1]]>y func[{y_,x_}]:=Evaluate[x+4]/;x[[1]]y:=Evaluate[x+y]/;x[[1]]>y func[{y_,x_}]/;x[[1]]

 Subject (listing for 'functions with conditions') Author Date Posted functions with conditions Andrew DuBui... 10/21/04 2:09pm Re: functions with conditions yehuda ben-s... 10/26/04 7:55pm Re: functions with conditions Andrew DuBui... 10/27/04 11:03am
 Next Comment > Help | Reply To Topic