Understanding Errors: G0064 Operand Missing

Introduction

Today we will help you to understand and resolve Error G0064: Operand Missing. We will answer the questions:

  • What is an operand?
  • How do common mathematical and non-mathematical operators interact with operands?
  • What are common causes of operand missing errors?

What is an operand?

An operand is a symbol that an operator operates on. For example, in the line below:

X = 4 + 5;

The plus sign is the operator and both 4 and 5 are operands.

Mathematical and Logical Operators

When you think of operators, the mathematical and logical operators tend to come to mind first. For example, operators like those shown in the table below.

Mathematical and Logical Operators
OperatorPurpose
+Addition.
*, .*Multiplication and element-by-element multiplication.
^Exponentiation.
==, .==Logical equality and element-by-element logical equality.
!==, .!==Logical not equal and element-by-element logical not equal
>, .>Greater than and element-by-element greater.

Operand Missing Errors with Mathematical and Logical Operators

Missing operand errors that occur with mathematical operators tend to be simple to understand and fix, so we will only show one example.

Example 1

Correct statementIncorrect statement
// Multiply 6 by 5 
// and print  
// the result
6.*5;
// The left-hand 
// operand is 
// missing
.*5;
The element-by-element multiplication operator requires two operands, one on the right-hand side and one on the left.The code snippet is missing the left side operand and will return the operand missing error.

Non-mathematical Operators

Unlike the logical and mathematical operators, many of the “other” operators are not commonly noticed or considered.

Non-mathematical Operators
OperatorDescriptionPurpose
,CommmaSeparates items in lists.
SpaceSeparates items in print statements and indices inside index brackets.
.PeriodSignifies all rows or all columns inside of index brackets.
:ColonCreates a continuous series of indices inside of index brackets.

Comma Operator Examples

Comma Operator Example One

Correct statementIncorrect statement
// Create a 4x2 matrix with 
// random normally 
// distributed numbers
X = rndn(4,2);
// No operands on either 
// side of the comma 
// operator
X = rndn(,);
The comma operator is used to separate the operands 4 and 2.The comma operator is used, but there are no operands for the comma operator to separate.

Comma Operator Example Two

Correct statementIncorrect statement
// Assign the element from  
// the 6th row and first 
// column to Z
Z = X[6,1];
// The operand to the right 
// of the comma operator 
// is missing
Z = X[6, ];
The comma operator separates the index operands 6 and 1.The comma operator is used, but there is not a column index on the right side of the comma.

Colon Operator Example

Operand missing statements with the colon operator will look like the previous comma operator errors.

Correct statementIncorrect statement
// Assign the 3rd to 5th 
// elements from the vector
// y to u
u = y[3:5];
// The operand to the
// right of the colon 
// operator is missing
u = y[3: ];
The colon operator separates the index operands 3 and 5.The colon operator is used, but there is not a column index on the right side of the colon.

The usage of space operator is probably the most likely “operand missing” error to trip up new GAUSS users.

The print statement takes a space-separated list of items to print. For example:

print 4 5 6;

will return:

4.0000    5.0000    6.0000

Similarly, we can print the same data with variables like this:

A = 4;
B = 5;

print A B 6;

And GAUSS will again return:

4.0000    5.0000    6.0000

So far this is quite simple and something you may have done without a thought. However, adding an operator can cause a problem. For example, because the print statement uses the space operator to separate the items to print, the statement:

print A + B;

is interpreted by GAUSS as the following instructions:

Print the value of A.
Print the value of +.
Print the value of B.

Therefore, when GAUSS gets to the + sign, it does not see enough operands, because it has already been told to print A.

You can resolve this by removing the space operator between A, + and B, or by adding parentheses around the statement.

A = 4;
B = 5;

// Option 1: Add parentheses 
// around the sum of A and B
print (A + B);

// Option 2: Remove space operator 
// to print the sum of A and B
print A+B;

The parentheses (or dropped spaces) only need to be around the operator. The table below shows a few variations and the resulting printed output.

StatementOutput
print (4 + 5) 6;
9.0000 6.0000
print (4 + 5)*6;
54.0000
print  ((4 + 5) / 6);
1.5000
print 4 5*6;
4.0000 30.0000

Conclusion

Congratulations! In today's blog, you have learned:

  • What mathematical, logical, and non-mathematical operands are in GAUSS.
  • Common causes of the G0064: Operand Missing error.

Further reading

  1. Understanding Errors | G0025 : Undefined symbol
  2. Understanding Errors: G0058 Index out-of-Range
  3. GAUSS Basics 6: Logical and relational operators

Leave a Reply