rCalc modification: using user-defined functions in rCalc 0.3.7
rCalc is a very good symbolic
calculator, very simple to use and it can be very useful when doing many
calculus, especially thanks to variables.
However, in two years of use, I felt the lack of a feature I really need:
the ability to create my own functions.
For exemple, create a function f that does f(x) = 2*x*x + 7*cos(x)
Then, it would just give you the result for x=2 when typing f(2), for example,
and it would speed up your work when you need to do several calculus with
the same function.
So I made this quick (and I'm sure, dirty) patch that enables you to:
- create functions: func <function_name>(x)=<your_function>
(example: func g(x)=2*x)
- list ALL the functions (that is, the ones you have created and the built-in ones): ls functions (or just ls
- use the function: function_name(mathematical_expression)
(example: g(cos(5*2 - 10)) or just g(1)
- remove an existing function: rm function_name (just
like you remove variables)
- the functions are saved in ~/.rcalc/ and are automatically
reloaded at startup
The functions are in fact a .c file compiled to a .so and dynamically linked
to the executable, all this when the func command is called. Therefore:
- you need a working gcc installed
- the functions take a little time to compile when you use the func
command (but it's usually less than 1 or 2 second)
- once the function is compiled, the call to the function and the calculus
is very fast, since the code is compiled.
- syntax errors are automatically detected by compiler and/or linker, and
prints message inside rCalc (see screenshot for the 2 error messages that
See this screenshot for these functions
Download the patch. (this patch
is against rcalc 0.3.7)
Apply it like this (for example) :
~/rcalc-0.3.7$ zcat ../rcalc-0.3.7-functions.patch.gz | patch -p1
Clément Bourdarias, last modification: June, 19th 2002.