File: ch05s03.html

package info (click to toggle)
genius 1.0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 25,308 kB
  • sloc: ansic: 75,620; xml: 71,565; sh: 4,445; makefile: 1,927; lex: 523; yacc: 298; perl: 54
file content (64 lines) | stat: -rw-r--r-- 8,397 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Používání funkcí</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Příručka k aplikaci Genius"><link rel="up" href="ch05.html" title="Chapter 5. Základy jazyka GEL"><link rel="prev" href="ch05s02.html" title="Používání proměnných"><link rel="next" href="ch05s04.html" title="Oddělovač"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Používání funkcí</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch05s02.html">Prev</a> </td><th width="60%" align="center">Chapter 5. Základy jazyka GEL</th><td width="20%" align="right"> <a accesskey="n" href="ch05s04.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="genius-gel-functions"></a>Používání funkcí</h2></div></div></div><p lang="en">
Syntax:
</p><pre lang="en" class="programlisting">FunctionName(argument1, argument2, ...)
</pre><p lang="en">
Example:
</p><pre lang="en" class="programlisting">Factorial(5)
cos(2*pi)
gcd(921,317)
</pre><p lang="en">

To evaluate a function, enter the name of the function, followed by the arguments (if any) to the function in parentheses. This will return the result of applying the function to its arguments. The number of arguments to the function is, of course, different for each function.
      </p><p>Existuje množství zabudovaných funkcí, jako třeba <a class="link" href="ch11s06.html#gel-function-sin"><code class="function">sin</code></a>, <a class="link" href="ch11s06.html#gel-function-cos"><code class="function">cos</code></a> a <a class="link" href="ch11s06.html#gel-function-tan"><code class="function">tan</code></a>. Můžete použít zabudovanou funkci <a class="link" href="ch11.html#gel-command-help"><code class="function">help</code></a> k výpisu dostupných funkcí nebo si přečíst kapitolu <a class="xref" href="ch11.html" title="Chapter 11. Seznam funkcí GEL">Chapter 11, <i>Seznam funkcí GEL</i></a>.</p><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Dokončování pomocí Tab</h3><p>Můžete používat klávesu Tab, aby vám Genius dokončoval názvy funkcí. Zkuste napsat prvních pár písmen názvu a zmáčknout <strong class="userinput"><code>Tab</code></strong>.</p></div><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Názvy funkcí rozlišují velikost písmen</h3><p>U názvů funkcí se rozlišuje velikost písmen. To znamená, že funkce pojmenované <code class="function">necoudelat</code>, <code class="function">NECOUDELAT</code> a <code class="function">NecoUdelat</code> jsou rozdílné funkce.</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-functions-defining"></a>Definování funkcí</h3></div></div></div><p lang="en">
Syntax:
</p><pre lang="en" class="programlisting">function &lt;identifier&gt;(&lt;comma separated arguments&gt;) = &lt;function body&gt;
&lt;identifier&gt; = (`() = &lt;function body&gt;)
</pre><p lang="en">
The <code class="literal">`</code> is the backquote character, and signifies an anonymous function. By setting it to a variable name you effectively define a function.
        </p><p lang="en">
A function takes zero or more comma separated arguments, and returns the result of the function body. Defining your own functions is primarily a matter of convenience; one possible use is to have sets of functions defined in GEL files that Genius can load in order to make them available.
Example:
</p><pre lang="en" class="programlisting">function addup(a,b,c) = a+b+c
</pre><p lang="en">
then <strong class="userinput"><code>addup(1,4,9)</code></strong> yields 14
        </p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-functions-variable-argument-lists"></a>Proměnný seznam argumentů</h3></div></div></div><p lang="en">
If you include <code class="literal">...</code> after the last argument name in the function declaration, then Genius will allow any number of arguments to be passed in place of that argument. If no arguments were passed then that argument will be set to <code class="constant">null</code>. Otherwise, it will be a horizontal vector containing all the arguments. For example:
</p><pre lang="en" class="programlisting">function f(a,b...) = b
</pre><p lang="en">
Then <strong class="userinput"><code>f(1,2,3)</code></strong> yields <code class="computeroutput">[2,3]</code>, while <strong class="userinput"><code>f(1)</code></strong> yields a <code class="constant">null</code>.
        </p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-functions-passing-functions"></a>Předávání funkcí funkcím</h3></div></div></div><p>V aplikaci Genius je možné předat funkci jako argument jiné funkci. To lze udělat buď pomocí „uzlů funkcí“ nebo anonymních funkcí.</p><p lang="en">
If you do not enter the parentheses after a function name, instead of being evaluated, the function will instead be returned as a ‘function node’. The function node can then be passed to another function.
Example:
</p><pre lang="en" class="programlisting">function f(a,b) = a(b)+1;
function b(x) = x*x;
f(b,2)
</pre><p lang="en">
        </p><p lang="en">
To pass functions that are not defined,
you can use an anonymous function (see <a class="xref" href="ch05s03.html#genius-gel-functions-defining" title="Definování funkcí">the section called “Definování funkcí”</a>).  That is, you want to pass a function without giving it a name.
Syntax:
</p><pre lang="en" class="programlisting">function(&lt;comma separated arguments&gt;) = &lt;function body&gt;
`(&lt;comma separated arguments&gt;) = &lt;function body&gt;
</pre><p lang="en">
Example:
</p><pre lang="en" class="programlisting">function f(a,b) = a(b)+1;
f(`(x) = x*x,2)
</pre><p lang="en">
This will return 5.
        </p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-functions-operations"></a>Operace s funkcemi</h3></div></div></div><p lang="en">
	      Some functions allow arithmetic operations, and some single argument functions such as <a class="link" href="ch11s05.html#gel-function-exp"><code class="function">exp</code></a> or <a class="link" href="ch11s05.html#gel-function-ln"><code class="function">ln</code></a>, to operate on the function. For example,
</p><pre lang="en" class="programlisting">exp(sin*cos+4)
</pre><p lang="en">
will return a function that takes <code class="varname">x</code> and returns <strong class="userinput"><code>exp(sin(x)*cos(x)+4)</code></strong>.  It is functionally equivalent
to typing
</p><pre lang="en" class="programlisting">`(x) = exp(sin(x)*cos(x)+4)
</pre><p lang="en">

This operation can be useful when quickly defining functions. For example to create a function called <code class="varname">f</code>
to perform the above operation, you can just type:
</p><pre lang="en" class="programlisting">f = exp(sin*cos+4)
</pre><p lang="en">
It can also be used in plotting. For example, to plot sin squared you can enter:
</p><pre lang="en" class="programlisting">LinePlot(sin^2)
</pre><p lang="en">
      </p><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p>Ne všechny funkce je možné použít tímto způsobem. Například, pokud použijete binární operaci, musí funkce přebírat stejný počet argumentů.</p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch05s02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch05.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch05s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Používání proměnných </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Oddělovač</td></tr></table></div></body></html>