HMath-2010: Working with HyperMath – Logical and Relational Expressions and Control Structures |
![]() |
![]() |
![]() |
![]() |
|
HMath-2010: Working with HyperMath – Logical and Relational Expressions and Control Structures |
![]() |
![]() |
![]() |
![]() |
In this tutorial, logical and relational expressions and control structures in the HyperMath scripting language will be examined.
Step 1: Launch HyperMath.
1. | From the Start menu, select All Programs > Altair HyperWorks > HyperMath. |
This launches HyperMath in the HyperMath GUI. Notice that by default, a file named Untitled1.hml exists in the Editor window. By default, the Authoring Mode is displayed as well.
Step 2: Using the Editor window, start a for loop which contains the Logical Operator or.
1. | In the Editor window, under the Untitled1.hml tab, enter the following line: |
for i=1,5,1 do
This initializes the variable i, which is a local variable to the for loop. The initial value of i is 1 and its value is increased by 1, up to the value of 5. Once the variable i reaches a value of 5, the for loop is evaluated for the last time and then terminated.
2. | Enter the following lines as the body to the for loop. |
print(i)
print(i<3 or i>4)
The print(i) command prints the value of variable i to the HMath window each time the loop is entered. The second print() statement uses the or command. The or command returns the first argument if the first argument is not false. If the first argument is false, then the second argument is returned.
3. | The for loop is completed with the end command. Type the following on line 4: |
end
The complete code written up to this point should be the following:
4. | Click Run File, ![]() |
1 |
true
2
true
3
false
4
false
5
true
Let’s evaluate these results. Remember that the or operator returns the first argument if the argument is not false. Otherwise, if the first statement is false, then the second argument is returned. When i is equal to 1 or 2, the first argument is not false, resulting in true being returned. When i is 3 or 4, the first argument is false, therefore the second argument is evaluated, which results in false. Finally, when i is 5, the first argument is again false, therefore the second argument is evaluated, resulting in true being returned.
5. | Save the file by going to File > Save As. Browse to the Desktop and save the file as Tutorial_2010.hml. |
The tab in the Editor window now says Tutorial_2010.hml.
Step 3: Create another for loop, this time with the Logical Operator and.
1. | In the Editor window, under the Tutorial_2010.hml tab, enter the following line at line 5: |
for j=1,5,1 do
This initializes the variable j which is a local variable to this for loop. The initial value of j is 1 and its value is increased by 1 up to the value of 5. Once the variable j reaches a value of 5, the for loop is evaluated for the last time and then terminated.
2. | Enter in the following lines as the body to the for loop. |
print(j)
print(j<3 and j>4)
The print(j) command prints the value of variable j to the HMath window each time the loop is entered. The second print() statement uses the and command. The and command returns the first argument if the first argument is false. If the first argument is not false, then the second argument is returned.
3. | The for loop is completed with the end command. Type the following on line 8: |
end
The complete code written up to this point should be the following:
4. | Click Run File, ![]() |
1
false
2
false
3
false
4
false
5
false
Let’s evaluate these results. Remember that the and operator returns the second argument if the first argument is not false. Otherwise, if the first statement is false, then the first argument is returned. When i is equal to 1 or 2, the first argument is not false, therefore the second argument is evaluated, which results in false being returned. When i is 3, 4 or 5, the first argument is false, therefore false is returned.
Step 4: Save the script Tutorial_2010.hml.
1. | From the File menu, click Save File to save the current file Tutorial_2010.hml. |
HMath-1000: Editing, Executing, Saving, and Plotting in HyperMath
HMath-1010: Working with HyperMath Authoring Mode
HMath-1020: Working with HyperMath Debugging Mode
HMath-2000: Working with HyperMath – Arithmetic and Relational Expressions and Control Structures
HMath-2020: Working with HyperMath – Functions and Matrix Operators
HMath-2030: Working with HyperMath – Plot Commands
HMath-3000: Working with HyperMath – String Library
HMath-3010: Working with HyperMath – Input/Output Library
HMath-3020: Working with HyperMath – Input/Output Library Continued
HMath-3030: Working with HyperMath – Batch Mode
HMath-4000: Using HyperMath Functions for Curve Fitting
HMath-4001: Using HyperMath for Material Characterization
HMath-4010: Solving Ordinary Differential Equations
HMath-4020: Solving Differential Algebraic Equations
HMath-4030: Optimization Algorithms in HyperMath
HMath-5000: Using HyperMath in HyperView Results Math
HMath-5001: Post Processing Results from FEA
HMath-5002: Registering a Function in HyperGraph 2D
HMath-5003: HyperMesh-HyperMath Cross Execution of a Tcl Script
HMath-5004: HyperMesh-HyperMath Cross-debugging of a Tcl Script