Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: functionalserver.id - Function Up: functionalserver - Tool Previous: functionalserver.compound - Function


functionalserver.compiled - Function



Package utility
Module functionals
Tool functionalserver


Create your own function


Synopsis
compiled(code, params)


Arguments

code in programmable expression string
    Allowed: string
    Default: ''
params in optionally parameters to be set
    Allowed: double array
    Default: unset


Returns
Functional or fail


Description

Create a function based on the programable string. The string should be a single expression, which can use the standard operators and functions and parentheses, having a single value as a result. The parameters of the function can be addressed with the p variable. This variable can be indexed in two ways. The first way is using the standard algebraic way, where the parameters are: p (or p0), p1, p2, ... . The second way is by glish indexing, where the parameters are addressed as: p[1], p[2], ... . The arguments are accessed in the same way, but using the variable name x. The compilation determines the number of dimensions and parameters of the produced function.
Operators are the standard operators (including comparisons, which produce a zero or one result; and conditional expression).
In addition to the standard expected functions, there is an atan with either one or two arguments (although atan2 exists as well), and pi and ee with no or one argument. The functional created behaves as all other functionals, and hence can be used in combinations.



Example
- a:=dfs.compiled('sin(pi(0.5) ) +pi'); # an example
- a.state()                             # and its result
[type=12, order=-1, progtext=sin(pi(0.5) ) +pi, ndim=0, npar=0, params=] 
- a.f(0)                                # note that a value is
                                        # necessary to produce non-empty 
                                        # result
4.14159 
-  a.fdf([0])                           # no derivatives: sine no parameters
[1:1,]
    4.14159] 
- b:= dfs.functional('compil','p*exp(-(x/p[2])^2') # try one to show error
SEVERE: Method define fails!
Illegal compiled expression:
No closing function paranethesis at: 
'p*exp(-(x/p[2])^2'''
- b:= dfs.functional('compil','p*exp(-(x/p[2])^2)') # try again
				        # Now a Gaussian with height
					# and halfwidth 0
- b.parameters()
[0 0] 
- b.setparameters([10 1])		# change to height 10 and
					# halfwidth 1 
10 1]
- b.f([-1,-0.5,0,.5,1])
[3.67879 7.78801 10 7.78801 3.67879] 
- # the next one is sync(x), catering for x=0
- # using the fact that comparisons deliver values. Note
- # the extensive calculation to make sure no divison by 0 
- synca:=
 dfs.compiled('( (x==0) * 1)+( (x!=0) * sin(x+(x==0)*1)/(x+(x==0)*1) )')
- synca.f([-1,0,1])
[0.841471 1 0.841471]  
- sin(1)/1
0.841471 

- # using conditional expressions:
- dfs.compiled('x==0 ? 1 : sin(x)/x').f([-1,0,1])
[0.841471 1 0.841471]





next up previous contents index
Next: functionalserver.id - Function Up: functionalserver - Tool Previous: functionalserver.compound - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15