1. Brief description of the program

"Blackboard" Calculator

Briefly:

The free "Blackboard" calculator for OS Windows is a very simple programming environment that allows you to organize calculations using cycles and branch operators. This makes it possible to numerically solve algebraic and differential equations, approximate certain integrals, sum series, etc. Almost all algorithms of computational mathematics can be implemented.

On the other hand, the "Blackboard" calculator can be used simply as a convenient multiline formula calculator, which does not require any mathematical knowledge, is suitable for household, accounting, engineering, etc.

Read more:

·Formulas in the calculator window are typed using the standard keyboard and do not contain any characters that are absent on it. But even under this condition, the writing of formulas is quite close to mathematical. So, for example, the module sign has the form "||", functions are applied to numbers without functional brackets, for example, sin0.1, and round "()", square "[]" and curly "{}" brackets are available to determine the order of arithmetic operations. To increase the speed of a set of formulas, templates of elementary functions are provided.

·You can simultaneously count several formulas, possibly related to each other. The latter means that quantities determined by some formulas can participate in other formulas. The simplest example: if a certain parameter is repeatedly included in the calculated expressions, then, having determined it with a separate formula, new parameter values ​​can be entered only in this one place.

·Formulas can be commented and saved to a file for future use. Thus, you can create a library of your programs, for example, for accounting or to fill out a tax return.

·The calculator allows you to organize loops like while-wend, do-until and branch operators if-elseif-else-endif. And also use the continue and break keywords in loops. There are tools for debugging computational formulas.

·The sequences of values obtained in the process of cyclic calculations are automatically displayed in the form of graphs. Thanks to the CanvasJS library, these graphs are interactive: they can be stretched to reveal small details, displaced along the horizontal axis for the same purpose, and, if there are several graphs, hide unnecessary ones.

·In order to start using the "Blackboard" calculator as a simple calculator, it is enough to spend one or two minutes reading the first part of the attached help file. For users who are familiar with the basics of programming, it takes the same amount of time to view the second part, which is intended for beginners. Studying a small number of syntax rules is facilitated by the fact that the calculator displays detailed error messages.

·The program interface is more than simple: in addition to standard controls and field for setting the number of fractional decimal places, there are only three buttons:

o"Start" - starts the calculation.

o“Stop” - stops calculations, which can then be continued again by the “Start” button. Pressing the Stop button again clears the memory so that the count can be started from the very beginning.

o"Function Templates" and "Keywords" are simply lists of templates to speed up a set of formulas.


2. Simple usage

With simple use, "Blackboard" Calculator is a worthy alternative to Windows calculator in both normal and scientific modes. Why this is so, you can learn from the next three sections of this guide, or by trying the calculator in work. All the above examples highlighted in black can be copied through the Windows clipboard and see how they work.


Arithmetic operations and elementary functions

Navigation: 2. Simple usage >

Return to chapter overview

2.1. Arithmetic operations and elementary functions

Everything becomes clear if you type = 2+3 in the calculator window and click the "Start" button. The formula you entered will remain unchanged, but the number 5 will appear below it. This is the result of the calculations.

Rule 1. An equal sign that precedes an arithmetic expression indicates to the calculator that the expression is to be evaluated.

For example, the expression 2+3 after pressing the "Start" button is not calculated, and instead of the result, an error message appears.

Arithmetic operations and brackets can be used in expressions, and elementary functions and constants shown in Table 1 are available for scientific calculations. The author tried to bring formulas as close as possible to the "school" style.

Tips:

·Clicking the "Start" button is equivalent to pressing the "F5" key.

·Before recalculating after making changes, the results of previous calculations do not need to be deleted - they are deleted automatically

·You can completely clear the calculator window using the "New" menu item in the "File" menu or the keyboard combination "Ctrl+N".

·Using the adjacent text box, you can set the number of decimal places to display. Valid values ​​range from 0 to 15.

Таблица 1. Арифметические операции, постоянные и элементарные функции

Arithmetic operations and constants |  | Functions
Addition | a+b | Trigonometric functions | sin(), cos(), tg(), ctg()
Subtraction | a—b | Inverse trigonometric functions | arcsin(), arccos(), arctg(), arcctg()
Multiplication | a*b | Exponential functions | exp(), sh(), ch()
Division | a:b или a/b | The natural logarithms and decimal | ln(), lg()
Exponentiation | a^b | Square root extraction | sqrt()
Parentheses | (), [], {} | Rounding to integer | round()
Number "pi" | pi=3.14... | Pseudo-random integer from 0 to n | random(n)
Euler's number | e=2,71... | Absolute value (module) | |a|

Tips:

·By applying functions to numbers (but not to expressions!), parentheses can be omitted. For example, lg0.17.

·The same is true if the function argument - a number or expression - is under the sign of the module. For example, lg|1+2|.

·The decimal separator can be either a comma or a period.

·For speed dialing, you can use function templates by clicking the "Function Templates" button. In the list that appears, select the required template - it will appear in the calculator window in the place indicated by the cursor.


2.2. Expression names

Formulas = 2+3 and x = 2+3 give the same result. The variant with the name of the expression, in this case, x, makes sense if one or more expressions using this value are counted. For instance,

x = 2+3

= (x-4):x

Tip. It is convenient and correct to assume that the value of this expression is stored in the name of an expression.

Rule 2. The name (identifier) ​​of the expression may consist of the letters of the Cyrillic and Latin alphabets, numbers and the underscore character "_", but cannot begin with a number.

For example, the sum2 = tg(x)+ctg(x) is correct, and 2sum = tg(x)+ctg(x) causes an error message.

Rule 3. You can use any number of named expressions, but so that the formula that defines each name is higher than any other expression that uses it.

The use of names makes sense, for example, in the following listing:

Salary = 4173.00

PIT = Salary*18/100

Military_Fees = Salary*1.5:100

SSC = Salary*22:100

Total_tax_load = PIT+Military_Fees+SSC;

To_payment = Salary-SSC-Military_Fees

These formulas for filling out the accounting statement are convenient in that for each employee you only need to enter his salary in the first line.

If the same bulky block is repeatedly included in the calculated expression, then assigning a name to this block can significantly speed up the set of formulas. For instance,

x = [sin(pi:8)+cos(pi:8)]:sqr3-1

= 1+x^2+x^3+x^4

Keep in mind that expression names are significantly more useful than what is contained in these examples. To some extent this is demonstrated in the following paragraphs.


2.3. Comments and saving formulas

A comment is any text following the first ";" (semicolon) to the end of the line. Usually comments explain what exactly is calculated. For instance:

; CREDIT ANNUITY PAYMENT CALCULATION

; -----------------------------------------

S = 1000 ; credit sum

I = 16:100 ; interest rate on the loan for the year

i = I:12 ; interest rate on the loan per month

n = 12 ; number of months for which credit is divided

; -----------------------------------------

A = S*i*(1+i)^n:[(1+i)^n-1] ; amount of monthly payment

P = A*12-S ; credit cost

This listing uses two types of comments: comments that occupy the entire line, and comments that follow the formula. There are three comments of the first type (two of them to improve readability) and six are of the second. After calculations, comments and formulas do not disappear.

In order not to type frequently used formulas each time, they can be saved to a file using the "Save" menu item in the "File" menu or the keyboard combination "Ctrl+S". You can return to these formulas using the "Open" item of the same menu or the keyboard combination "Ctrl+O".

Tip. Calculation results are automatically deleted before saving, so this does not need to be done manually.


Управлющие структуры

Navigation: »No topics above this level«

Return to chapter overview

3. Control structures

Control structures are loops and branch operators, with the help of which algorithms are built for the numerical solution of most problems of computational mathematics. The implementation of control structures in the "Blackboard" calculator is described in the following paragraphs. It is close to that adopted in other programming languages, so users who are familiar with a programming language can only pay attention to paragraph 3.2. "Once keyword", 3.4. "Integration with MS Excel", 3.6. "Continue and break keywords" and 4. "Debugging the application".

For beginners, examples of simple algorithms for the numerical solution of algebraic equations, ordinary differential equations and the approximate calculation of certain integrals are given. If you copy these examples into the calculator window using the Windows buffer, you can see how they work.


3.1. While and until loops

Computations are called loop when a certain block of formulas is calculated repeatedly while some logical condition is satisfied. Cyclic calculations are based on recurrence formulas, characterized in that some variables calculated by their previous values. Here is an example recurrence formula:

n = n+1

This is not the equation. The formula means that the value of the variable n standing on the left side of the formula is obtained by adding 1 to the previous value of this variable located on the right side. Naturally, in this process it is necessary to start with something. Therefore, before looping, the initial value of n must be set to, say, zero.

Two types of loop can be used in the "Blackboard" calculator:

·while(condition)...wend

·do...until(condition)

The while, wend, and do, until keyword pairs limit the block of formulas called the body of the loop. For example, the loop that was just mentioned can be organized as follows:

n = 0

while(n<10)

n = n+1

wend

Here, the body of the loop consists of one recurrence formula n = n+1, the initial value is given by the formula n = 0 located outside the loop, and the inequality n<10 is a logical condition. After starting the calculations with the "Start" button, 1 will be added to the number n at each step. And this will continue as long as the inequality n < 10 is fulfilled. When this inequality ceases to be fulfilled, the loop will finish its work, and the value of n will naturally be equal to 10.

Here is a more meaningful example of calculating the sum of the squares of the first 10 natural numbers:

n = 0

S = 0

while(n<10)

n = n+1

S = S+n^2

wend

= S

In this example, the body of the loop consists of two recurrence formulas. Accordingly, two initial values are set outside the cycle.

The last line is needed to see the answer. The fact is that the while-wend cycle is a cycle with a precondition, that is, if the condition is violated, the formulas in the body of the cycle are not calculated. Therefore, immediately before exiting the cycle, formulas are not calculated and their values ​​are accordingly not displayed.

The do-until loop acts just like the while-wend loop, but it is a loop with a postcondition, that is, the logical condition is checked not before, but after the loop body is executed. Therefore, the body of the loop is in any case executed at least once. In addition, the exit from the loop occurs not when the logical condition is violated, but when it is is fulfilled.

Tip. Which of these cycles to use is a matter of taste. Sometimes one is more convenient, sometimes another.

Here is a solution to the same problem of the sum of the squares of the first 10 natural numbers using the do-until loop:

x = 0

S = 0

do

n = n+1

S = S+n^2

until(x>=10)

Note that unlike the previous example, the string "= S" is not needed here. When the loop ends, the answer will be below the formula S = S+n^2.

Comment. There can be several cycles in the program, and they can be nested into each other.

Example. Find a solution to the equation ex-3x = 0 with 10-7 accuracy.

The first way. We use the method of changing the sign. Since for x = 0 the left side of the equation is positive, and for x = 1 it is negative, the root must be in this interval. Therefore, we calculate the left side of the equality, starting from 0 and moving towards 1 with a step h = 0.001. As soon as its value changes from positive to negative, the root will be passed and, therefore, found with an accuracy equal to h. We type:

h = 0.001

x = 0

do

x = x+h

f = e^x-3*x

until(f<0)

and run the calculation. After the stop, it turns out that the sign reversal occurred at a value of x = 0.620. The accuracy in this case is obviously insufficient, since the step h is chosen too large. To achieve the given accuracy, the step had to be chosen equal to 10-7, but such a calculation would take too much time.

We take advantage of the fact that the calculation narrowed the interval in which the root of the equation should be. Therefore, we repeat the calculations with the step h = 10–7 ensuring the given accuracy, choosing as the initial value the last known point at which the function is still positive, that is, x = 0.619. Now the result is satisfactory: a sign reversal occurred at x = 0.6190613, in which the left side of the equation is -1.5158339*10-8.

In order not to change the formulas manually, the described method can be automated using nested loops:

h = 0.1

x = 0

while(h>10-7)

do

x = x+h

f = e^x-3*x

until(f>0)

x = x-h

h = h/10

wend

= x

In this listing, the familiar do-until loop, which calculates the sign of the left-hand side of the equation f, is used as the inner loop, and the initial condition for this loop and the accuracy parameter h are set in the outer while-wend loop. Namely, the formula x = x-h determines the initial value of x, and the formula following it reduces the step h by 10 times. A condition for exiting the external loop is to achieve the required accuracy h<10-7 .

The second way. We use the method of contraction mappings, writing the equation in the form x = e^x/3. We type:

x = 0

do

x_old = x

x = e^x/3

until(|x-x_old|<10^-8)

Here the variable x_old contains the previous value of x, and the new one is calculated in the formula below. The condition for exiting the loop is that consecutive values ​​of x_old and x differ only in the 8th character after zero.

Example. It is required to calculate the integral of the function f(x) = sin2x on the interval from 0 to π / 2 with an accuracy of 0.001.

We use the rectangle method. We type:

h = 0.0001

x = 0

S = 0

while(x<pi/2)

x = x + h

S = S+[sin(2x)]^2*h

wend

and run the calculations. The result is 0.78545184. Since this integral calculated by analytical methods is π/4 = 0.78539816, we can conclude that step h was chosen correctly. Usually, when calculating the integrals, the exact result is not known. Therefore, choosing any value of step h, it is necessary to decrease it sequentially until the calculation result ceases to change in the desired (in this case, fourth) sign after 0. This algorithm is easy to implement by adding an external loop with this exit condition:

h = 0.001

S = 0

do

h = h/2

S_old = S

x = 0

S = 0

while(x<pi:2)

x = x+h

S = S+[sin(x)]^2*h

wend

until(|S-S_old|<10^-4)

= S

Tips:

·Indention's in formulas that facilitate their perception do not need to be done. They are automatically installed after the first count.

·If the logical condition appearing in the loop is made up with an error, then the loop can turn out to be infinite, that is, the calculations will never end. To stop the calculator, you need to use the "Stop" button or the "Esc" key. A message box appears asking you to stop or continue the calculation.


3.2. Once keyword

The recurrence formulas and the initial values ​​corresponding to them are located in different parts of the program: the formulas are inside the cycle, and the initial values ​​are outside. In the "Blackboard" calculator, you can combine them using the once keyword in form once(expression). For example, the recurrence formula n = n+1 and the initial value x = 0 can be combined into the formula n = once(0)+1.

Formally, the once keyword is a function that, upon first access to it, returns the value of its argument, and on subsequent calls, the current value of the variable that it initiated. Thus, the example of the previous paragraph with the calculation of the sum of squares can be written as follows:

do

n = once(0)+1

S = once(0)+n^2

until(n = 10)

Although this form of writing recurrence formulas is more compact (all in one place) and is shorter, then the traditional form will be used.


3.3. Logical expressions

The condition for exiting the loop is a logical expression. In addition, logical expressions play a major role in the branches that will be discussed in Section 3.5. To compose logical expressions, you need to use the comparison operators and logical operations shown in the following table.

Table 2. Comparison operators and logical operations

Comparison operators |  | Logical operations
More (or equal) | a>b (a>=b) | "And" | And
Less than (or equal to) | a<b (a<=b) | "Or" | Or
Equal (not equal) | a=b (a<>b) | Negation | Not

The result of the calculation of logical expressions is the logical constants True and False.

Example. What is greater than epi or pie?

To find out, the easiest way is to type the following:

= e^pi>pi^e

True

Calculation result: True, that is, the first expression is greater than the second.

Logical expressions can be combined using logical operations. Let X and Y be logical expressions.

·X And ​​Y is true if and only if both expressions are true. For example, the expression x>0 And x<1 means that x belongs to the interval (0, 1).

·X Or Y is true if and only if at least one of the expressions is true. For example, the expression x<0 Or x>1 means that x does not belong to the interval [0, 1].

·Not X is true if and only if X is false. For example, Not x>0 means x<=0.

Tip. In order to remember these rules, we denote the truth through 1, and false — through 0, which is the standard in programming. Then And coincides with the usual multiplication, and therefore this operation is called logical multiplication. Similarly, Or is called logical addition, since for 0 and 1 it coincides with the addition of numbers (with the easily remembered exception 1+1 = 1).

Rule 4. There should be spaces in the formulas around logical operators.

Example. Players Sam and John in each round randomly either get a point or get nothing. Who will score 10 points first?

Sam = 0

John = 0

do

Sam = Sam + random(1)

John = John + random(1)

until(Sam = 10 Or John = 10)

Recall that the random(1) function returns 0 or 1 with equal probabilities. The condition for exiting the cycle is that at least one of the players scored 10 points.


3.4. Graphical display of results

By running the example with the game given at the end of the previous paragraph, you can only find out who won. To follow the twists and turns of the game, you need to use the export (name) keyword. In fact, this is a function that, in the process of counting, collects all the values ​​of the expression specified by its argument. After the end of the count, the collected data is automatically displayed in the form of a graph.

The following formulas differ from those considered in the previous paragraph by the presence of two export() functions, one for each of the players:

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 is this:

The horizontal axis is always the number of the cycle, and the vertical axis is the value of the variable in this cycle. In this case, it is the number of wins of this or that player. It can be seen that the struggle was intense - first one player, then the other came forward.

The best way to figure out how you can manipulate the graphs is to run formulas in the Blackboard calculator.

When you hover the mouse over the nodal points of the chart, a tooltip appears with the coordinates of this point, that is, the cycle number and the value of the variable.

The menu in the upper right corner of the Chart Canvas allows you to print charts or save them as a jpeg or png image.

Clicking on the legend item located at the bottom of the canvas hides / shows the corresponding color graph. Moreover, after the removal of the highest (lowest) graph, all others are rebuilt so as to occupy the entire height of the canvas.

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

Tip. If the graphs are stepped, then, most likely, there are not enough fractional decimal places specified.

Graphs built on a large number of points can be scaled and then moved with the mouse. This means that an area selected with the mouse that is narrower than the canvas is automatically stretched to the full width of the canvas. The resulting window can be moved along the horizontal axis in order to view the graphs in detail in neighboring areas. The scaling operation can be repeated several times until all the details of the graphs behavior are visible.

This process is controlled by only two buttons that appear in the upper right corner of the canvas when an area is selected. The left button allows you to move the window, and the right button removes the scaling and restores the original view of the chart.

To demonstrate the usefulness of scaling, consider formulas that tabulate the function
y = sin[1/(|x-0.5| + 0.000001)] on the interval [0, 1].

x = 0

h = 0.00001

do

y = sin[1/(|x-0.5|+0.000001)]

x = x+h

export(y)

until(x>=1)

We get the following graph:

How the graph behaves in the middle, that is, in the vicinity of the point x = 0.5, (the number of cycles is 50,000) is absolutely not clear. Let's select the interval from x = 0.49 to x = 0.51:

Again, nothing is visible. And, finally, from the fourth time in the range from x = 0.4996. up to x = 0.5004 we get the required:

For example, now we can say that there is a local maximum at the point x = 0.5, at which the function takes on the value y = -0.66.

Export() functions can in principle be located anywhere. But you need to understand that the values ​​they save depend on their location, namely: the current value of the argument is captured at the time of execution of this function. Therefore, it is recommended to place export() functions only in loops and, preferably, at the end of the loop body.

If there are several loops, sequential or nested within each other, then the export() function of the same argument is best placed in all of these loops to collect all the information about the change in the observed value.

The same applies to blocks of branching constructs like if...endif, which will be discussed in the next section.

Finally, any mathematical expression can be used as an argument to export(). For example, you can switch to a logarithmic scale by replacing export(y) with export(ln(y)).


3.5. Branch constructions

This is the only branching construction available in the "Blackboard" calculator. It is generally accepted:

if(logical_expression)

block

elseif(logical_expression)

block>

else

block

endif

The keywords if, elseif, else, and endif limit the blocks of formulas from which only one is executed. Namely, the first block from above is executed, for which a logical expression is true. If all logical expressions are false, the else block is executed.

There may be several elseif blocks, or may not be at all. The else block can be only one or, in general, be absent.

The branch constructions in question can be nested in each other.

Example. Players Sam (S) and John (J) play the next game. Each of them rolls a dice and adds to his points the dropped amount of points. But, if exactly 15, 30 or 45 points are scored, then all points “burn out”. The game goes to 50.

S = 0

J = 0

while(S<=50 And J<=50)

S = S+random(5)+1

if(S = 15 Or S = 30 Or S = 45)

S = 0

endif

export(S)

J = J+random(5)+1

if(J = 15 Or J = 30 Or J = 45)

J = 0

endif

export(J)

wend

Here the role of the dice is played by the expression random(5)+1, which takes with equal probability the values ​​1, 2, ..., 6. Branching is used in the simplest form: only the required keywords if and endif are present.

Let's complicate this example. Let, as before, the players add the number of points that fell out when throwing the dice. But, if any of the players breaks ahead, he receives a one-point bonus. If the players have an equal number of points, then they will be fined five points. Here are the formulas corresponding to this game:

S = 0

J = 0

while(S<=50 And J<=50)

S = S+random(5)+1

J = J+random(5)+1

if(S>J)

S = S+1

elseif(S<J)

J = J+1

else

S = S-5

J = J-5

endif

export(S)

export(J)

wend


3.6. Continue and break keywords

The continue keyword can only be inside a loop. The following algorithm of its action is generally accepted: all formulas following it are skipped to the end of the body of the loop, and the next step of the loop begins by checking the while or until logical expressions.

Typically, the continue keyword is used inside the branching block, since the actions described above, performed without any condition, make little sense. In the "Blackboard" calculator, this keyword has its own condition: continue(condition), when it is fulfilled, the generally accepted algorithm described above works, and if it is not fulfilled, the keyword is simply ignored.

Example. The following formulas display in MS Excel or Notepad all integers from 1 to 10 except 5 and 7.

n = 0

while(n<=10)

n = n+1

continue(n = 5 Or n = 7)

export(n)

wend

Warning. You need to be careful using the continue keyword, as it is easy to make a mistake and get an "infinite loop".

For example, such an error is just a permutation of two lines in the previous example:

n = 0

while(n<=10)

continue(n = 5 Or n = 7)

n = n+1

export(n)

wend

The break keyword causes the loop to exit immediately. For the same reasons as described above, in the "Blackboard" calculator, this keyword is used with the condition: break(condition). The exit from the loop occurs only if the condition is true.

Example. Someone per unit time t makes with equal probability a step forward or a step back. How long does it take for him to go forward or backward at a distance S of 10 steps?

t = 0

S = 0

while(1)

t = t+1

S = S+2*random(1)-1

break(|S| = 10)

wend

An infinite while loop is used here, the condition of which is always satisfied. The loop is exited using the break keyword when the distance becomes 10. Do not be afraid that this distance will never be reached - according to probability theory, on average, you will need only 100 units of time.

Tip. Many programmers believe that the break and continue keywords violate the structure of the program code and prefer to do without them. So, if possible, it is better to do so.


4. Debugging the Application

Debugging formulas in the "Blackboard" calculator is facilitated by the fact that the calculator displays messages about most possible syntax errors and even on some run-time errors (division by 0, the logarithm of a negative number, etc.).

In addition, debugging capabilities are expanded due to the specifics of the calculator, which, at the end of the count, displays the values ​​of the expressions in their right part below the formulas. But only those that were calculated immediately before the completion of the calculations. For example, the variable n in the listing below is not visible, since it was calculated before the start of the loop. The variable m inside the loop is also not visible, since after the last check of the loop condition its body was not executed.

n = sin(pi/2)

m = 0

while(m<10)

m = m+1

wend

Such a calculator action algorithm is explained by the fact that it makes sense to display only the last, final values ​​of the variables. This circumstance can be used by adding debug lines of type "= variable_name". Continuing the previous example, add these lines and run the calculation:

n = sin(pi/2)

m = 0

while(m<10)

m = m+1

wend

= n

1

= m

10

The stop(condition) keyword .

To look at the values ​​of expressions at any time, and not just at the end of calculations, you need to use the stop keyword, which stops the loop when the condition is satisfied. For example, stop(1) stops the loop after each step.

In the following example, after stopping by condition, only the expressions counted in the body of the loop are visible, and their past values, and even more so the future ones, are not visible:

n = sin(pi/2)

m = 0

while(m<10)

m = m+1

3

stop(m = 3)

-> Циклические вычисления остановлены по условию

n = n-1

-2

wend

= m

= n

In the case of stopping calculations with the stop keyword, the loop step is completed. This means that the calculator processes the entire body of the loop, and not just the formulas preceding the stop keyword. For example, in the considered example, when stopping, it calculates not only the variable m that precedes the keyword stop, but also the variable n that comes after.

Tip. After stopping by the stop() keyword, the calculating can be continued by clicking the "Start" button. Moreover, the calculation can be continued by changing the stopping condition.