LET
uses mathematical formula notation to compute a value and assign
it to a variable. The vector on the left side of the equal sign is
given the result of the formula on the right side of the equal
sign. The formula may be a mathematical expression or a logical
expression (see below). The formula may contain variable names
(vectors), named variables (enums and named constants), numerical
constants, and literal vectors. It may also invoke any of a number
of You may omit the LET command name. The equal sign is sufficient. For example, LET a = sin(3.14159/180*30) can also be written as: a = sin(3.14159/180*30) If you omit the LET command name and happen to choose a result variable name that is also a command name, you will get an error. For example, data = SQRT(1 2 3 4 5) produces the error message "ERROR: Invalid variable format "=" (Number, variable, sequence, or list expected) in command DATA,...". That is because "data" is also a command name and is interpreted as such because it is the first word on the line. It is best to change the result variable name, but if you insist on using it, you can put the LET command word at the beginning of the line like this: LET data = SQRT(1 2 3 4 5) and that will be accepted. The valid operators are shown in the following table. Use these operators exactly as you would in a formula. Their precedence is defined so that, in the absence of parentheses, the mathematical operations are executed in the customary order. The concatenation operator (&) appends the vector on its right to the vector on its left. It is of the same precedence as addition and subtraction.
The minus sign
"-" in its common usage has four different meanings: as
a subtraction operator (a - b), as a "change sign"
operator (-a), as an indicator that a literal number is less than
zero (-4.5E-3), and
as a hyphen in a variable name ("class-grades") . When
used following a variable name, you should put a space before the
minus sign so it isn't interpreted as a hyphen. Otherwise, you
will get a syntax error message. If As always, a decimal number must have at least one place before the decimal point, e.g., "0.5" instead of ".5". The following table lists the mathematical functions that are valid in the formulas of the LET command. These functions have the highest precedence and are executed prior to any of the above mathematical operators. The functions behave exactly as do the commands having the same name. The mathematical functions, when used with LET, can take only one argument. This means they cannot accept keywords as they can when used as commands. Therefore a function like STDEV that allows a keyword when used as a command will perform only its default behavior when it is used in the LET command. To make those computations that are subject to keywords available, new names are defined with the keyword added as part of the name, separated by an underscore. For example a standalone "STDEV POP" command would become "STDEV_POP" when used in the LET command and "SORT DESCENDING" becomes "SORT_DESCENDING" in the LET command. Similarly, the INTEGER command has been broken into four separate function names based on its keywords: INTEGER_CEILING, INTEGER_FLOOR, INTEGER_ROUND, and INTEGER_TRUNCATE. The table also lists these variations. Within the LET command all these function names are "reserved". That means that you cannot use any variable name in a LET command that is the same as a function name because the variable name will be interpreted as a function name.
The mathematical functions can be invoked with or without parentheses as follows. LET vec1 = LOG vec2 or LET vec1 = LOG(vec2) The parentheses are required if the argument is an expression: LET vec1 = LOG(vec2 + vec3) Although parentheses are used for determining execution order, they can also be used to enter a literal vector into the equation. For example, this is legal: LET vec1 = LOG You can also use multiple and sequence format (m#n and m,n respectively) to express literal (unnamed) vectors. For example, the above line could also be written like this using the sequence format: LET vec1 = LOG(1,5)
The LET command can also be used to assign the result of logical expressions to variables. The result of a logical expression is always either true or false. The constants true and false are predefined, so the following assigns true to vec1: LET vec1 = true The following also assigns true to vec1, since that is the result of the logical expression on the right hand side of the equal sign (the LET may be omitted as shown here): vec2 = sin(0.1) < 0.5 The logical expressions may be more complex, as in this arbitrary example (assumes a, b, and c are defined earlier in the program): vec3 = a < b + 4 and c > 0 and sin(0.1) < 0.5 Remember that all the tests, such as <, =, and between only compare the first element of the vectors involved in the test. You can use variables containing logical values anyplace that logical expressions are allowed: IF vec1 and vec2 ... END or even in another LET command: vec4 = vec1 or vec3 and sqrt(x) > 3
If you define a subroutine that has only one input variable and one output variable, you can invoke that subroutine within a LET command. For example, if you define a subroutine of the form NEWCMD MYSUB inVec outVec where you can use any name you like instead of "mysub", you can invoke it in a LET command as you would any mathematical function: . . . You can see an example of such a usage in the example column to the right.
The operators that you use in the LET command, such as "+", "-", "^", etc. are actually converted into invocations of the ADD, SUBTRACT, POWER, etc. commands to be executed. The "&" operator is converted to a COPY command. The function names you use, such as ABS, SIN, etc. get converted into the commands of the same name. The "=" sign is converted to a COPY command. For example, the command: LET A = B + C will be converted internally (not visible to you) into: ADD B C internal#001 where internal#001 is an internal temporary variable assigned to hold the intermediate result. Therefore, it will take two debugging steps, one for the plus operator (ADD) and one for the equals (COPY) operator, to step through that command line. But, if you call for the same computation using the ADD command: ADD B C A it will be completed in one debugging step. |
This example graphs a circle: NAME 0.017453292519943295 degToRad 'Multiply degrees by this to get radians
This example prints out some powers of two: 'Program to print out the first 11 The output of this program is: powersOfTwo: (1.0 2.0 4.0 8.0 16.0 32.0 64.0 128.0 256.0 512.0 1024.0)
This example computes the sum of a power series: 'To cover a distance, first you must
The next example compares a program that uses the LET command with a similar program that does not use the LET command.
INCLUDE "lib\mathConstants.txt"
Both versions produce the same graph:
This next example shows the use of a literal vector "0,720" in the LET command instead of a variable name. The first line computes the sin of the angles from 0 to 720 degrees in steps of one degree. The second line graphs the result: LET vec1 = sin(3.14159/180 * The concatenation operator (&) appends the vector on its right to the vector on its left. For example, LET vec1 = (1 2 3) & 4,6 & 7,10 is equivalent to COPY (1 2 3) 4,6 7,10 vec1 In either case, vec1 becomes vec1: (1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0) Here's an example of invoking a user-defined subroutine in a LET command: 'User-defined subroutine to convert With this output: temperaturesC temperaturesF If you don't like the long names of some of the commands, such as INTEGER_CEILING, you can write a short subroutine to invoke it with whatever name you like. For example: NEWCMD CEIL inVec outVec This subroutine can then be used in a LET command like this: result = CEIL(vecA) Instead of this: result = INTEGER_CEILING(vecA) |