Difference between revisions of "Function calls and parameters"

m
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:Analytica User Guide]]
+
[[Category: Analytica User Guide]]
<breadcrumbs>Analytica User Guide > Using Expressions > {{PAGENAME}}</breadcrumbs>
+
[[Category: Functions]]
  
 +
<breadcrumbs>Analytica User Guide > Expressions > {{PAGENAME}}</breadcrumbs>
  
Analytica provides a large number of built-in functions for performing mathematical, array, statistical, textual, and financial computations. There are also probability distribution functions for uncertainty and sensitivity analysis. Other more advanced or specialized functions are described in [[Other Functions]]. The Enterprise edition of Analytica also includes functions for accessing external ODBC data sources. Finally, you can write and use your own user-defined functions (see [[Building Functions and Libraries]]).
 
  
'''Position-based function calls''': The conventional position-based syntax to call a function uses this form:
+
Analytica provides a rich set of built-in functions including [[Math functions]], [[Array Functions and Operators|array]], [[Statistical functions|statistical]],  [[Text, Date, Math, and Financial Functions]], [[Probability Distributions]], [[Spreadsheets and Analytica|spreadsheet functions]] and more. You can also write and use your own [[User-defined Functions and Libraries]]).
 +
 
 +
Here are some simple expressions involving functions.
 +
:<code>[[Exp]](1) &rarr; 2.718281828459</code>
 +
:<code>[[Sqrt]](3^2 + 4^2) &rarr; 5 </code>
 +
:<code>[[Mod]](7, 3) &rarr; 1</code>
 +
:<code>[[Normal]](mean: 500, sdeviation: 100)</code>
 +
:<code>[[FindInText]]('ONE', 'Result is one or two.', caseInsensitive: True, return: 'S') &rarr; 'one'</code>
 +
 
 +
You can see
 +
==Position-based function calls==
 +
 +
With this conventional syntax, you just list the parameters after the function name between parentheses in the same sequence that they are defined for the function:
 
:<code>FunctionName(param1, param2, ...)</code>
 
:<code>FunctionName(param1, param2, ...)</code>
  
You follow the function name by a comma-separated list of parameters enclosed between parentheses, with the parameters in the specified sequence. In most cases, parameters can them- selves be expressions built out of constants, variable names, operators, and function calls. Here are some simple examples of expressions involving functions.
+
In a function call, each parameter may be a constant, name of a variable, or a more complex expression with operators, or function calls. In some cases, a parameter must be of an expected type -- for example, the second parameter of Sum must be an index to sum over:
:<code>Exp(1) &rarr; 2.718281828459</code>
+
:<code>[[Sum]](Cash_by_year, Year)</code>
:<code>Sqrt(3^2 + 4^2) &rarr; 5 Mod(7, 3) &rarr; 1</code>
 
:<code>Pmt(8%, 30, -1000) &rarr; $88.83</code>
 
:<code>Normal(500, 100)</code>
 
  
Some functions have optional parameters. In that case, you can simply omit the trailing parameters that will use their default values.
+
Some parameters are [[Optional parameter|optional]], in which case you may omit them and the function will use default values.
  
'''Name-based function calls''': Analytica also offers name-based parameter syntax as an alternative for calling most functions: You name each parameter, followed by a colon (:) and the value passed to that parameter. Since the parameters are named, you can list them in any order. For example, this function has four parameters, of which you can provide any two to define the distribution:
+
== Name-based function calls==
:<code>Lognormal(median, gsdev, mean, stddev)</code>
 
  
Calling it using name-based syntax:
+
With name-based syntax to call a function, you name each parameter, followed by a colon (:) and the value passed to that parameter.  You may list the parameters in any order, and omit any optional parameters. For example, [[LogNormal]] has four parameters, of which you may provide any two to define the distribution:
:<code>Lognormal(mean: 10, stddev: 1.5)</code>
+
:<code>[[LogNormal]](median, gsdev, mean, stddev)</code>
  
is equivalent to the following using position-based syntax, which uses commas to indicate that the first two parameters are omitted:
+
You can call it using name-based syntax:
:<code>Lognormal( , , 10, 1.5)</code>
+
:<code>[[LogNormal]](mean: 10, stddev: 1.5)</code>
  
because <code>mean</code> and <code>stddev</code> (standard deviation) are the third and fourth parameters. Name-based syntax is useful for functions with many optional parameters. It’s usually easier to read name-based function calls because you don’t need to remember the ordering of the parameters.
+
This is equivalent to this position-based syntax, using extra commas to indicate omitted parameters:
 +
:<code>[[LogNormal]]( , , 10, 1.5)</code>
 +
 
 +
Name-based syntax is useful for functions with many optional parameters, since you don't have to count commas and remember the order of the parameters. It’s usually easier to read name-based function calls.
 +
 
 +
You may mix position- and named-based syntax if you use position for the initial parameters:
 +
:<code>[[LogNormal]](10, stddev: 4)</code>
 +
You may not  use a position-based parameter after a name-based parameter:
 +
:<code>[[LogNormal]](mean: 10, 1.5) &rarr; ''syntax error'' </code>
  
 
==See Also==
 
==See Also==
 +
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
 +
* [[Using Named Parameters]]
 
* [[Function Parameter Qualifiers]]
 
* [[Function Parameter Qualifiers]]
 
* [[Parameter qualifiers]]
 
* [[Parameter qualifiers]]
 
* [[ParameterEnumeration]]
 
* [[ParameterEnumeration]]
 +
* [[Conventions for parameters and operands]]
 +
* [[Function_parameter_qualifiers#Repeated_parameters_.28....29|Repeated parameters]]
 +
* [[Repeated Parameter Forwarding]]
 +
* [[User-Defined Functions]]
 +
* [[Expression Syntax]]
 +
* [[Expression Assist]]
 +
* [[Procedural Programming Example]]
 +
* [[Summary of Programming Constructs]]
 +
</div>
 +
  
 
<footer>IF a THEN b ELSE c/ {{PAGENAME}} / Math functions</footer>
 
<footer>IF a THEN b ELSE c/ {{PAGENAME}} / Math functions</footer>

Latest revision as of 20:51, 29 December 2017



Analytica provides a rich set of built-in functions including Math functions, array, statistical, Text, Date, Math, and Financial Functions, Probability Distributions, spreadsheet functions and more. You can also write and use your own User-defined Functions and Libraries).

Here are some simple expressions involving functions.

Exp(1) → 2.718281828459
Sqrt(3^2 + 4^2) → 5
Mod(7, 3) → 1
Normal(mean: 500, sdeviation: 100)
FindInText('ONE', 'Result is one or two.', caseInsensitive: True, return: 'S') → 'one'

You can see

Position-based function calls

With this conventional syntax, you just list the parameters after the function name between parentheses in the same sequence that they are defined for the function:

FunctionName(param1, param2, ...)

In a function call, each parameter may be a constant, name of a variable, or a more complex expression with operators, or function calls. In some cases, a parameter must be of an expected type -- for example, the second parameter of Sum must be an index to sum over:

Sum(Cash_by_year, Year)

Some parameters are optional, in which case you may omit them and the function will use default values.

Name-based function calls

With name-based syntax to call a function, you name each parameter, followed by a colon (:) and the value passed to that parameter. You may list the parameters in any order, and omit any optional parameters. For example, LogNormal has four parameters, of which you may provide any two to define the distribution:

LogNormal(median, gsdev, mean, stddev)

You can call it using name-based syntax:

LogNormal(mean: 10, stddev: 1.5)

This is equivalent to this position-based syntax, using extra commas to indicate omitted parameters:

LogNormal( , , 10, 1.5)

Name-based syntax is useful for functions with many optional parameters, since you don't have to count commas and remember the order of the parameters. It’s usually easier to read name-based function calls.

You may mix position- and named-based syntax if you use position for the initial parameters:

LogNormal(10, stddev: 4)

You may not use a position-based parameter after a name-based parameter:

LogNormal(mean: 10, 1.5) → syntax error

See Also


Comments


You are not allowed to post comments.