next up previous contents
Next: Branches Up: Programming Previous: Programming


Programs can be created and run interactively. Programming a function is demonstrated in the following example of a function ttwo(x), which multiplies its argument by $2$. After the definition it can be used like any other Jasymca function.
>> function y=ttwo(x) y=2*x; end
>> ttwo(3.123)
ans = 6.246
Following the keyword function is the prototype with a return variable y. This replaces the construct return y of other programming languages.

If functions are to be reused later, they should be written to a textfile and saved somewhere in Jasymcas searchpath. The filename must be the function name extended by ``.m'', in the present example ttwo.m. In subsequent sessions the function ttwo can be used without separately loading the file. Several installed functions of Jasymca are provided using this mechanism.

Helmut Dersch