Abs: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| (3 intermediate revisions by the same user not shown) | |||
| Line 4: | Line 4: | ||
== Useful tricks with <tt>abs</tt> == | == Useful tricks with <tt>abs</tt> == | ||
Using the <tt>abs</tt> function, it is possible to | Using the <tt>abs</tt> function, it is possible to produce makeshift <tt>min</tt> and <tt>max</tt> behaviour using ASCEND relations. For example, | ||
<source lang=a4c> | <source lang=a4c> | ||
a,b IS_A factor; | a,b IS_A factor; | ||
max IS_A factor; | min, max IS_A factor; | ||
max = a + ((b-a) + abs(b-a))/2; | max = a + ((b-a) + abs(b-a))/2; | ||
min = a + ((b-a) - abs(b-a))/2; | |||
</source> | </source> | ||
See also [[conditional modelling]] for more complex syntax for this kind of 'conditional' behaviour. | |||
[[Category:Syntax]] | [[Category:Syntax]] | ||
Latest revision as of 15:22, 13 May 2012
The abs function in ASCEND returns the absolute value of its argument. This function should be used with caution in models because, being a non-smooth function, it can damage the convergence of many of the Newton-based solver algorithms, such as QRSlv.
Useful tricks with abs
Using the abs function, it is possible to produce makeshift min and max behaviour using ASCEND relations. For example,
a,b IS_A factor; min, max IS_A factor; max = a + ((b-a) + abs(b-a))/2; min = a + ((b-a) - abs(b-a))/2;
See also conditional modelling for more complex syntax for this kind of 'conditional' behaviour.