Charta Software
Back to the base
E-mail:
Wachtwoord:
Aangemaakt door op 2005-12-02 20:18:53
Laatst gewijzigd op 2008-06-05 16:02:05

A straight forward function

Numerical square root calculation

The previous example showed you a simple function evaluation and you probably didn't have any difficulties. The next step is slightly more difficult and lets you add, modify and run a straight forward function. It is straight forward, because the function doesn't use any data or call other functions, but it does show you the basics of editing.

Creating a new function
  • Open the functions node within the Math package
  • Add a new function by inserting a row in the functions table
  • Set the name of the new function to "Square root"
  • Open the newly created function by pressing Enter

Now you have created and opened a new function, which we will use to numerically calculate the square root of a number. The next step is to set the function's interface (its result value and parameters) and create the necessary local variables.

Setting the interface and variables
Error: "Unknown element: p" at line 17 and column 4 Go to error

In the next steps we will implement the function body to iteratively adjust the height and width of a virtual rectangle, while keeping its surface equal to the number we wish to calculate the square root of. We stop when the height and width are equal. When both sides are equal, we have found the square root.

Implementing the function body
Error: "Unknown element: p" at line 39 and column 4 Go to error

Now the function is pretty much finished, but it cannot be used yet. This is because Charta indicates that there are still problems to be solved.

Solving the problem
Error: "Unknown element: br" at line 70 and column 4 Go to error

If all went well, then you have successfully finished your first Charta function. Now let's test it.

Evaluating
Error: "Unknown element: br" at line 85 and column 4 Go to error
Switching views
Error: "Unknown element: p" at line 93 and column 4 Go to error

The next step in using functions is to use them for data selection and manipulation. The next example will show you how.