home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / sci / math / symbolic / 3304 < prev    next >
Encoding:
Text File  |  1992-12-17  |  1.9 KB  |  58 lines

  1. Newsgroups: sci.math.symbolic
  2. Path: sparky!uunet!utcsri!torn!watserv2.uwaterloo.ca!watdragon.uwaterloo.ca!watdragon!drclark
  3. From: drclark@daisy.uwaterloo.ca (David R. Clark)
  4. Subject: Re: Help with user defined functions in Maple.
  5. In-Reply-To: jmp1@ns1.cc.lehigh.edu's message of 17 Dec 92 06:07:55 GMT
  6. Message-ID: <DRCLARK.92Dec17103709@daisy.uwaterloo.ca>
  7. Sender: news@watdragon.uwaterloo.ca (USENET News System)
  8. Organization: University of Waterloo, Waterloo, Ontario, Canada
  9. References: <1992Dec17.060755.53708@ns1.cc.lehigh.edu>
  10. Date: Thu, 17 Dec 1992 15:37:09 GMT
  11. Lines: 45
  12.  
  13. jmp1@ns1.cc.lehigh.edu (JEFFREY MICHAEL PARSONS) writes:
  14.  
  15.    From: jmp1@ns1.cc.lehigh.edu (JEFFREY MICHAEL PARSONS)
  16.    Subject: Help with user defined functions in Maple.
  17.  
  18.    I tried defining a function in Maple V r1.1 like this:
  19.  
  20.    f := proc(x)  if x<0 then -1 else 1 fi;  end;
  21.  
  22.    I could then type f(3) or f(-100) and get the correct result.  The
  23.    problem is that I can't integrate it, etc.  I always get:
  24.  
  25.    Error, (in f) cannot evaluate boolean.
  26.  
  27.    Is there a better way to be doing this kind of thing?
  28.  
  29.    Thanks.
  30.    -- 
  31.  
  32. The procedure you have written does not allow for the possibility that
  33. the parameter may be an expression that cannot be compared to zero.
  34.  
  35. The procedure can be better defined as:
  36.  
  37. f := proc(x)  if not type(x,numeric) then 'procname(x)'
  38.               elif x<0 then -1
  39.               else 1 fi;
  40.      end;
  41.  
  42. When supplied with a non-numeric parameter this new function returns
  43. without evaluating.  It can be numerically integrated, plotted, 
  44. and manipulated in Maple.  Allowing symbolic integration of user defined
  45. functions is a much more difficult question.
  46.  
  47. You can also work with your original function by using the Maple
  48. quote operator to disable evaluation of the expressions, e.g.:
  49.  
  50. > f := proc(x)  if  x<0 then -1 else 1 fi;  end;
  51.  
  52. f := proc(x) if x < 0 then -1 else 1 fi end
  53.  
  54. > evalf(Int('f(x)',x=-1..1));
  55.  
  56.                                        0
  57.  
  58.