Re: What am I doing wrong?
- Subject: [mg2192] Re: What am I doing wrong?
- From: ianc (Ian Collier)
- Date: Fri, 13 Oct 1995 06:24:51 GMT
- Approved: usenet@wri.com
- Distribution: local
- Newsgroups: wri.mathgroup
- Organization: Wolfram Research, Inc.
- Sender: daemon at wri.com ( )
In article <45d24c$63m at ralph.vnet.net>, JSNW at msg.ti.com (Jason Welter) wrote: > Kemp[z_] := If[z>5,Kemp=gft[z] + 21,Kemp=gft[z] - 21] > gft[z_] := If[z>5,gft=z^2 + 2,gft=z^2 - 2] > Kemp[4] > > SetDelayed::write: Tag Integer in (-14)[z_] is Protected. > $Failed > SetDelayed::write: Tag Integer in 7[z_] is Protected. > $Failed > (-14)[4] I can't reproduce exactly what you are seeing, but I think that your assignments to Kemp and gft withing your definitions are redundant and problematic. I only see a problem when I call Kemp for the second time. Changing the definition slightly (Kemp2 and gft2 below) eliminates the problem. In your example in calling Kemp you then set the symbol Kemp to a certain value (after you defined the function) and this value is used when you attempt to call the function Kemp for the second time. In[1]:= Kemp[z_] := If[z>5,Kemp=gft[z] + 21,Kemp=gft[z] - 21] In[2]:= gft[z_] := If[z>5,gft=z^2 + 2,gft=z^2 - 2] In[3]:= Kemp[4] Out[3]= -7 In[7]:= Kemp[5] Out[7]= (-7)[5] In[4]:= Kemp2[z_] := If[z>5,gft2[z] + 21,gft2[z] - 21] In[5]:= gft2[z_] := If[z>5,z^2 + 2,z^2 - 2] In[6]:= Kemp2[4] Out[6]= -7 In[8]:= Kemp2[5] Out[8]= 2 --Ian ----------------------------------------------------------- Ian Collier Technical Sales Support Wolfram Research, Inc. ----------------------------------------------------------- tel:(217)-398-0700 fax:(217)-398-0747 ianc at wri.com Wolfram Research Home Page: http://www.wri.com/ -----------------------------------------------------------