12.07.2015 Views

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10: Expressions 75++x--xThis expression increments the variable x. The value of the expression is thenew value of x. It is equivalent to the expression x = x + 1.This expression decrements the variable x. The value of the expression is thenew value of x. It is equivalent to the expression x = x - 1.x++ This expression causes the variable x to be incremented. The value of theexpression is the old value of x.x-- This expression causes the variable x to be decremented. The value of theexpression is the old value of x.It is not currently possible to increment index expressions. For example, you mightexpect that the expression v(4)++ would increment the fourth element of the vector v, butinstead it results in a parse error. This problem may be fixed in a future release of <strong>Octave</strong>.10.8 Operator PrecedenceOperator precedence determines how operators are grouped, when different operatorsappear close by in one expression. For example, ‘*’ has higher precedence than ‘+’. Thus,the expression a + b * c means to multiply b and c, and then add a to the product (i.e., a+ (b * c)).You can overrule the precedence of the operators by using parentheses. You can thinkof the precedence rules as saying where the parentheses are assumed if you do not writeparentheses yourself. In fact, it is wise to use parentheses whenever you have an unusualcombination of operators, because other people who read the program may not rememberwhat the precedence is in this case. You might forget as well, and then you too could makea mistake. Explicit parentheses will help prevent any such mistake.When operators of equal precedence are used together, the leftmost operator groupsfirst, except for the assignment and exponentiation operators, which group in the oppositeorder. Thus, the expression a - b + c groups as (a - b) + c, but the expression a = b = cgroups as a = (b = c).The precedence of prefix unary operators is important when another operator followsthe operand. For example, -x^2 means -(x^2), because ‘-’ has lower precedence than ‘^’.Here is a table of the operators in <strong>Octave</strong>, in order of increasing precedence.statement separators‘;’, ‘,’.assignment‘=’. This operator groups right to left.logical "or" and "and"‘||’, ‘&&’.element-wise "or" and "and"‘|’, ‘&’.relational‘’, ‘!=’, ‘~=’, ‘’.colon ‘:’.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!