Creating Summation Function
There is a detailed description of creation of Summation function.
At first:
- Use the File menu.
-
Select New.
- Select Function.
Now you can see Code Editor. It's empty.
Click with the right mouse button anywhere in the Code Editor window.
In the shortcut menu select Properties and enter function name in the field Analysis Technique|Name at the Properties window.
Enter the name: "Summation". After filling name field this function name will appear at the end of the list of functions at Browser. Default function Type is DoubleFunction. Summation is Double function so keep this field without changes. We want to write this function on C# so keep field Language without changes too.
Click the right mouse button anywhere in the Code Editor window again. Now in the shortcut menu select Parameters. Enter input parameters for this Function. This Function calculates summary of Length last values, passed by Values parameter.
To add parameters click right mouse button on the Parameters box and in the shortcut menu select Add Parameter and special form will appear.
In this form enter Parameter name, Parameter type, Parameter default value, Parameter description and if necessary mark that parameter is Reference. Than click Save if you want to save this parameter or Discard if you don't.
For this function at first enter Parameter name ("Values") and select Parameter type ("DoubleSeries") and than click Save.
Than again click right mouse button on the Parameters box and in the shortcut menu select Add Parameter. Now enter Parameter name ("Length") and select Parameter type ("Integer") and click Save.
So we filled Parameters box:
For this simple function we don't need to use References and Variable Store.
Now enter the code of Summation function into the Code Editor window.
At first we need to define the variables and initialize them. Declare sum variable to store resulting summary and set it's default value to zero:
double sum = 0;
To calculate summary of all passed values we need to use loop.
- Set integer valiable i to zero: int i = 0;
- Set condition when to stop the loop: i < Length;
- Set what to do with i after each loop iteration: i++;
- Specify the action we need to perform in the loop (in this case we want to add i-th value to the currently counted summary): sum = sum + Value[i].
for ( int i = 0; i < Length; i++ ) sum = sum + Values[i];
Then we move to assigning calculated summary, stored in sum variable to Value variable (the actual value of the function).
Value = sum;
After all listed actions click right mouse button anywhere in the Code Editor window and select Build Analysis Technique. If there are no errors in the Function it will appear in the list of functions at Browser with the green tick. Otherwise Task List will appear. For example if you forgot semicolon it will display in Task List with indication of concrete line and file name with error.
When you will find the error and correct it click the right mouse button anywhere in the Code Editor window and select Build Analysis Technique again. If there are no errors in the Function now Task List will be empty and function name will appear in the list of functions at Browser with the green tick.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5