"Blackboard" Calculator

## Integration with MS Excel

In the game example at the end of the previous paragraph, you can only find out who won. To follow the ups and downs of the game you need to use the keyword export (name). In essence, this is a function that collects all the values ​​of a quantity of interest indicated by its argument and exports them to MS Excel.

Sam = 0
John = 0
do
Sam = Sam + random(1)
John = John + random(1)
export(Sam)
export(John)
until(Sam = 10 Or John = 10)

The result, automatically opening in MS Excel, is shown in the left figure:

The first place in the column is the name of the exported variable, and its values ​​are listed below. There are exactly as many columns in the table as there are times in the formulas the export() function.The columns go in the same order as the corresponding export() functions.

The accuracy of the values ​​recorded in the table is the same as for the numbers displayed in the calculator window (that is, it is determined by the number in the "Signs after 0" field).

For exported data, you can construct a graph in the usual way (see, for example, Как построить график в Excel) or use other computing capabilities provided by MS Excel. In the example under consideration, the following graph was obtained:

If MS Excel is not installed in the system, the calculator will offer to output the results to a csv-file (a text file, the data in which is separated by tabs), and will display them in Windows Notepad. In this example, the contents of this file are shown in the upper right figure. The records from the csv file can then be processed in an existing table processor or in another program for processing numerical data.

There is one important limitation on the use of the export keyword. Violation of this condition leads to incorrect data output

Rule 5. If there are several export keywords in the calculator window, they should all be in the body of the same cycle and, moreover, if the cycle contains an if-endif branch or continue, (see in two sections below), then all of them must be located either outside the branch or in the same branch block.
More formally: between any pair of export keywords in a program, there can NOT be keywords while, wend, do, until, if, elseif, else, endif and continue.

This restriction can be circumvented by recounting the task several times with a different arrangement of the export keywords in a particular cycle or block.

Comment. The array exported to MS Excel should not contain more than 1,048.576 elements for versions 2007+ and 65.536 for earlier versions.

Example. Solve the differential equation dx/dt = cos(x) on the interval [0, π / 2] with the initial condition x(0) = 1. We use the Euler method:

h = 0.1
t = 0
x = 1
do
x = x+cos(x)*h
t = t+h
export(x)
export(t)
until(t>pi/2)

After exporting the data to MS Excel, the following graph of the dependence x(t) is obtained: