Step 3 - How to Execute Scripts
In this page, Let's use one of special features of RINPn: script execution.
Sponsored Link
The RINPn can execute a script file written in the "Vnano", to perform procedural, algorithmic, or other complicated calculations.
What is the Vnano?
The vnano is a compact script engine & language for embedded use in applications. The vnano has simple C-like syntax. For details of syntax of the Vnano, see: "Features of the Vnano as a Language" in the Vnano Official Website. To create a script of the Vnano, no development environments (e.g.: compiler) is required. Simply create a text file of which name ends with the extention ".vnano", and write code in there.
Example Script
There is an example script file "Example.vnano" in the folder of the RINPn. This example script calculates the numerical integration value of cos(x) from 0 to 1:
// Integration parameters
double A = 0.0;
double B = 1.0;
int N = 100000;
// Integrant function
double f(double x) {
return cos(x);
}
// Perform integration
double delta = (B - A) / N;
double value = 0.0;
for(int i=0; i<N; ++i) {
double x = A + i * delta;
value += ( f(x) + f(x+delta) + 4.0 * f(x+delta/2.0) ) * delta / 6.0;
}
// Output result
output(value);
For detailed explanations about the above code, see: https://www.vcssl.org/en-us/code/archive/0001/7800-vnano-integral-output/
How to Execute a Script in GUI mode
To execute this script in the GUI mode, there are two methods:
- Method 1: Click "Script" button on the window, and select the script file to be executed.
- Method 2: Input the name or path of the script file to "INPUT" text-field, and press Enter key or click "=" button to execute it.
Choose the favorite method from the above.
For example, execute the example script in the previous section "Example.vnano":
Example.vnano
OUTPUT:
0.8414709848
As the above, the output value of the script will be displayed on the "OUTPUT" text-field. The output value "0.8414709848" is matched well with the value of sin(1) which is the theoretical integration value of cos(x) from 0 to 1, so it indicates that the above example script has run correctly.
By the way, if you want to execute a script file in the different folder with the folder at which you has launched the RINPn, it is necessary to input the absolute file path ("C:\...\Example.vnano", "/home/.../Example.vnano", etc.) of the script to execute it. (If you are using Microsoft® Windows®, right-click the script file with pressing Shift key, and then you can copy the file path from the right-click menu.)
How to Execute a Script in CUI mode
As same as the GUI mode, you can execute a script on CUI mode, by inputting the name or the path of the script file.
For executing a script file in the current directory, pass only name of the script file to the "rinpn" command:
rinpn Example.vnano
(Result) 0.8414709848
When a script file is in a different directory with the current directory, you can specify the relative file path of it, instead of the file name:
rinpn ./example/Example.vnano (Execute a script in "example" directory)
Also, if necessary, you can specify the absolute file path as follows,
rinpn "/home/.../Example.vnano" (For Linux®, etc.)
About Optimization Levels:
When Processing of a Script Is Heavy ...
By the way, when processing of a script is heavy, it might be helpful to raise the optimization level specified in "Settings.txt" as "acceleratorOptimizationLevel", to make the processing faster.
Even when the value of the optimization level is 0, probably the processing speed is enough to use the RINPn in the standard way of a calculator software, so the default value of the optimization level is set to 0. However, if you execute numerical calculation programs frequently on the RINPn, the processing speed might not be sufficient with the default optimization level.
Get New Scripts from the Code Archive
You can write new scripts from scratch, but sometimes the code archive in the official website of the VCSSL/Vnano may be helpful:
- Code Archive » Vnano
- https://www.vcssl.org/en-us/code/#vnano
Useful scripts are being distributed on the code archive, with commentary articles explaining algorithms, background knowledge, and so on.
Solve The Lorenz Equations Numerically |
|
|
Solve the Lorenz equations, and output data to plot the solution curve (well-known as the "Lorenz Attractor") on a 3D graph. |
Output Data of Numerical Integration For Plotting Graph |
|
|
Example code computing integrated values numerically, and output data for plotting the integrated functions into graphs. |
Compute Integral Value Numerically |
|
|
Example code computing integral values numerically by using rectangular method, trapezoidal method, and Simpson's rule. |
- Introduction - Overview of RINPn and How to Get Started
- Step 1 - How to Use in GUI Mode (on the Calculator Window)
- Step 2 - How to Use in CUI Mode (on the Command-Line Terminal)
- Step 3 - How to Execute Scripts
- Step 4 - How to Add Functions/Variables by Scripts (Library Scripts)
- Step 5 - Implement Functions/Variables in Java™ (Plug-in Development)
- Step 6 - How to Embed into Other Software
- Appendix - List of Built-in Functions/Variables