Operators Functions Order of Operations Mixed Mode Arithmetic VOID Data. Syntax and type conventions Using the Script window interface

Similar documents
Chapter 4: Basic C Operators

9 Using Equation Networks

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Arithmetic. 2.2.l Basic Arithmetic Operations. 2.2 Arithmetic 37

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

3.1. Chapter 3: The cin Object. Expressions and Interactivity

Introduction to Programming

Product Price Formula extension for Magento2. User Guide

Chapter 2. Outline. Simple C++ Programs

Programming in QBasic

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

Functions and Inverses ID1050 Quantitative & Qualitative Reasoning

Operators and Expression. Dr Muhamad Zaini Yunos JKBR, FKMP

Numerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Process Optimization

Goals for This Lecture:

TECH TIP VISION Calibration and Data Acquisition Software

Chapter 4. Operations on Data

ANSI C Programming Simple Programs

The Graphing Calculator

Expressions and operators

Introduction to Engineering gii

CT 229 Java Syntax Continued

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Engineering Problem Solving with C++, Etter/Ingber

MYSQL NUMERIC FUNCTIONS

Maths Functions User Manual

2 Making Decisions. Store the value 3 in memory location y

Chapter 3: Operators, Expressions and Type Conversion

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Data Types and Basic Calculation

Sketchify Tutorial Properties and Variables. sketchify.sf.net Željko Obrenović

Expressions. Eric McCreath

Unit 3. Operators. School of Science and Technology INTRODUCTION

JAVA OPERATORS GENERAL

The Expressions plugin PRINTED MANUAL

Julia Calculator ( Introduction)

CHAPTER 3: CORE PROGRAMMING ELEMENTS

Arithmetic and Logic Blocks

Program Workspace. Why numerical methods? Problem examples Why programming? Why numerical methods and programming? Why VBA?

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Operators & Expressions

Introduction to Python, Cplex and Gurobi

Lecture 2 FORTRAN Basics. Lubna Ahmed

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Python Lists: Example 1: >>> items=["apple", "orange",100,25.5] >>> items[0] 'apple' >>> 3*items[:2]

STATGRAPHICS Operators

The Expressions plugin PRINTED MANUAL

Chapter 3. built in functions help feature elementary math functions data analysis functions random number functions computational limits

C++ Programming Lecture 11 Functions Part I

Expressions. Eric Roberts Handout #3 CSCI 121 January 30, 2019 Expressions. Grace Murray Hopper. Arithmetic Expressions.

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Department of Computer Science

Primitive Data Types: Intro

Program Structure and Format

Introduction to C++ Introduction and History. Characteristics of C++

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

C Programs: Simple Statements and Expressions

9. Elementary Algebraic and Transcendental Scalar Functions

C++ Overview. Chapter 1. Chapter 2

Chapter 1 Introduction to MATLAB

4.7a Trig Inverses.notebook September 18, 2014

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Dr Richard Greenaway

Walt Whitman High School SUMMER REVIEW PACKET. For students entering AP CALCULUS BC

Built-in Types of Data

Learning the Language - V

ME 142 Engineering Computation I. Unit 1.2 Excel Functions

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Javascript Bignum Extensions

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14

MATHEMATICAL / NUMERICAL FUNCTIONS

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Watershed Sciences 4930 & 6920 GEOGRAPHIC INFORMATION SYSTEMS

10 Using the PCFL Editor In this chapter

Solving for the Unknown: Basic Operations & Trigonometry ID1050 Quantitative & Qualitative Reasoning

Scheme Quick Reference

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Green Globs And Graphing Equations

JME Language Reference Manual

MTH 120 Fall 2007 Essex County College Division of Mathematics Handout Version 6 1 October 3, 2007

VBScript: Math Functions

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

Appendix B The Floating Point Instruction Set

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object

Chapter 3: Expressions and Interactivity

CO212 Lecture 10: Arithmetic & Logical Unit

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

Python Programming: An Introduction to Computer Science

Declaration and Memory

Scheme Quick Reference

Mapping Figures Workshop University of Utah July 6, 2012 Martin Flashman A.1 Suppose f is a function determined by the following table :

Secondary Math 3- Honors. 7-4 Inverse Trigonometric Functions

6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Transcription:

Introduction Syntax Operators Functions Order of Operations Mixed Mode Arithmetic VOID Data Introduction Map Layer Mathematics Algebraic statements are used to perform the basic mathematical operations and functions that deal with constants and map layers. This is known as Layer Math, or Overlay Math. Algebraic operators and functions are performed on every cell in a specified map layer. If a map layer is multiplied by 1000, then each cell in the input map layer will be multiplied by 1000. If one map layer is subtracted from another, then all common cells are subtracted. Using More Than One Map Layer in an Algebraic Statement All the map layers that appear in an algebraic statement must have the same cell resolution, orientation, and at least one common cell. These parameters can be determined from the Information window of each map layer. The Script Window Operators and functions are applied in the Script window. To open a new Script window select New Script from the Windows menu. Syntax and type conventions Using the Script window interface Syntax Algebraic statements follow the same convention as operation statements in the Script window. They begin by stating the name of the new map layer to be generated. This is followed by an = symbol and then an algebraic expression. UG-ALG-1

Algebraic expressions can contain map names, operators, bracketing, and function names. An algebraic statement must contain at least one map layer name. The basic syntax is: newmap = expression; Algebraic statements can be complex. MFworks can handle complex, bracketed expressions that include multiple functions and operators, such as: map3 = map1 + (5.0 * SIN(map2)) / AVG(map2, 6); OR map4 = map3 * 3.1415 + MAX(map1, map2, map3); Note: Algebraic statements cannot contain map Operations. UG-ALG-2

Operators Note: In the functions below, a, b, and c represent either a map name or a value. Performing Basic Math on Map Layers Determining Where One Map Layer is Greater Than Another Determining Where Two or More Relational Conditions are True 1) Monadic (one operator followed by one operand) Operator Meaning Example - Negative -a! or NOT Logical not!b or NOT b 2) Dyadic (Math) (one operator separating two operands) Operator Meaning Example * Multiplication a * b ^ Power/Exponent a^b (i.e., a b ) / Division a / b (i.e., a b) % Modulus a % b (i.e., a MOD b) + Addition a + b - Subtraction a - b 3) Dyadic (Relational) (one operator separating two operands) Operator Meaning Example < Less than a < b > Greater than a > b <= Less than or equal to a <= b >= Greater than or equal to a >= b == Equal to a == b!= Not Equal to a!= b 4) Dyadic (Logical) (one operator separating two operands) Operator Meaning Example or OR Logical or (a!= b) (a > c) & or AND Logical and a &!b UG-ALG-3

Functions Note: In the functions below, x represents either a map name or an expression. Applying Trigonometric Functions to a Map Layer Converting Fixed and Floating Point Data Types Finding the Maximum Non-VOID Value in a Stack of Map Layers Counting the Number of Cells With the Same Value 1) Trigonometric Functions SIN(x) COS(x) TAN(x) ARCSIN(x) ARCCOS(x) ARCTAN(x) return sine of x (x in radians) return cosine of x (x in radians) return tangent of x (x in radians) return arcsine of x return arccosine of x return arctangent of x 2) Logarithmic Functions EXP(x) return e x LOG(x) return log x (base e) LOG10(x) return log x (base 10) 3) Mode Functions FLOAT(x) TRUNC(x) PREC(x,y) convert x to a floating point entity convert x to an integer entity set precision of x to y decimal places 4) List Functions MAX(x1, x2, ) return maximum of list MIN(x1, x2, ) return minimum of list AVG(x1, x2, ) return average value of list MAXNV(x1, x2, ) return maximum of non-void values in list MINNV(x1, x2, ) return minimum of non-void values in list AVGNV(x1, x2, ) return average value of non-void values in list 5) Miscellaneous Functions ABS(x) return absolute value UG-ALG-4

COUNT(map) return cell count in map Order of Operations Introduction MFworks follows standard order of operations priority logic. This means that expressions are evaluated according to the priority assigned to operators in the expression. You may override the priority system by using brackets, as these have the highest priority. For example, multiplication and division are higher order operators than addition and subtraction: 6 + 5 * 4 = 26 whereas, (6 + 5)*4 = 120 Priority System The priority system is as follows: 1) (highest) ( ) Brackets 2) - (negation),!, NOT Monadic 3) ^ Power/Exponent 4) *, /, % Multiplication, Division, Modulus 5) +, - (minus) Addition, Subtraction 6) <, <=, >, >= Relational 7) ==,!= Relational 8) AND, & Boolean And 9) (lowest) OR, Boolean Or Operators at the Same Level Operators that occur at the same level are evaluated from left to right: 3 1 2 map1 == map2 <= map3 >= map4 is equivalent to: map1 == ((map2 <= map3) >= map4) 2 4 3 1 map1 * map2 + map3 % (map4 - map5) is equivalent to: (map1 * map2) + (map3 % (map4 - map5)) UG-ALG-5

Mixed Mode Arithmetic MFworks follows standard mixed mode arithmetic logic when operands of different data types appear in an algebraic expression. When mixing floating point data type and integer data type map layers, the data type of the resultant map layer depends on the order of the map layers and the operators and functions that are used. All Integer/Fixed Point Data Operands If a given operator or function is passed all integer values, the result will be integer values. Using a Floating Point Operand If any operand of an operator or function is a floating point value, then all operands are promoted to floating point data and the result will be a floating point value. The following are exceptions to the rule: 1) All Trigonometric and Logarithmic functions return floating point data. 2) The PREC and FLOAT functions return floating point data. 3) The TRUNC and COUNT functions return integer data. 4) The relational operators (<, <=, >, >=, ==,!=) and the logical operators (AND, OR, NOT, &,,!) return integer results (1 or 0, where 1 = true and 0 = false). Constants Constants in an expression are considered to be integers unless they contain a decimal point. Using Brackets to Control Mixed Mode Arithmetic The extent of mixed mode arithmetic is bound by brackets. For example: 1. (3/4) + 5.0 is 5.0 not 5.75 and: 2. FLOAT(3/4) + 5.0 is also 5.0, not 5.75 but: 3. (3./4) + 5.0 is 5.75 and: 4. (FLOAT(3)/4) + 5.0 is 5.75 In the first example: (3/4) + 5.0, (3/4) is not promoted to floating point arithmetic because of the brackets. There are no decimal places allowed in integer arithmetic, therefore, 3 divided by 4 equals zero. Note: Integer math always truncates the result. UG-ALG-6

In the second example: FLOAT(3/4) + 5.0, the function FLOAT does not convert 3 divided by 4 into a floating point number, because, by order of operations, the 3 divided by 4 is performed first. FLOAT (0) equals zero. Again the presence of the brackets bound the rules of mixed mode arithmetic. In the third example: (3./4) + 5.0, mixed mode arithmetic is performed. The 4 is promoted to the floating point number 4.0 because a floating point value occurs within the brackets. In the final example: (FLOAT(3)/4) + 5.0, the order of operations makes the FLOAT (3) operation occur before dividing the 3 by 4, therefore, this operation is equivalent to the third example. Algebraic statements may contain up to 50 levels of bracketing. Expressions may be embedded in functions as in other programming languages. VOID Data How VOID is Handled in an Expression VOID is a special data value in MFworks. It is considered to be the absence of data. VOID appears in an expression only when it is part of a number list such as in a relational expression. Any expression that is performed on a cell with the value VOID, will result in VOID. For example: 1) 1 + VOID = VOID 2) SIN (VOID) = VOID 3) MAX (VOID, 1, 3) = VOID Exceptions to the Rule: VOID Always Returns VOID There are a few exceptions where VOID is handled differently: 1) The relational comparison operators == (equal) and!= (not equal) can be used to compare VOID to VOID cells. These operators will return either 1 or 0, but never VOID (i.e., VOID == VOID returns 1 while VOID = value returns 0 ). The other relational operators (<, <=, >, >=) will return VOID if the cell in one of the operand map layers is VOID (e.g., newmap = (maplayer1 >= VOID)). This is UG-ALG-7

because relationship is calculated mathematically and VOID has no numerical value. VOID > VOID returns VOID VOID <= value returns VOID value <= value returns either 1 or 0 2) The Non-VOID (NV) functions AVGNV, MAXNV, and MINNV ignore VOID cells. These functions will only return VOID if all the operand cells being compared are VOID. In the case of the average function, AVGNV, VOID cells do not contribute to the count of values to average. For example: while AVG (VOID, 1, 3) = VOID, MAX (VOID, 1, 3) = VOID, MIN (VOID, 1, 3) = VOID, AVGNV (VOID, 1, 3) = 2 MAXNV (VOID, 1, 3) = 3 MINNV (VOID, 1, 3) = 1 Expressions Not Containing VOID That Result in VOID Expressions that do not contain VOID may result in VOID if: 1) There is a floating point overflow or underflow (i.e., the number exceeds 1.0E38 or is less than 1.0E-38). 2) The result of the expression is undefined (e.g., division by 0, TAN(π/2), Log(-1)). UG-ALG-8