1 Arithmetic Expressions and Built in Functions 1.ARITHMETIC OPERATORS There are five basic arithmetic operations with Fortran. These are given in the.

Slides:



Advertisements
Similar presentations
Chapter 3: Expressions and Interactivity. Outline cin object Mathematical expressions Type Conversion and Some coding styles.
Advertisements

Study Guides Quantitative - Arithmetic - Numbers, Divisibility Test, HCF and LCM Mycatstudy.com.
Chapter 2 Basic Elements of Fortan
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
Solving Linear Equations
HAWKES LEARNING SYSTEMS math courseware specialists Copyright © 2010 Hawkes Learning Systems. All rights reserved. Hawkes Learning Systems: College Algebra.
INTRODUCTION TO PYTHON PART 1 CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Real Numbers and Algebra
Real Numbers and Algebraic Expressions
Quantitative - Arithmetic - Numbers, Divisibility Test, HCF and LCM
Sets and Expressions Number Sets
Operaciones y Variables
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Algebra Form and Function by McCallum Connally Hughes-Hallett et al. Copyright 2010 by John Wiley & Sons. All rights reserved. 6.1 Integer Powers and the.
Fall, 2006Introduction to FORTRAN1 (2 + 2 = ???) Numbers, Arithmetic Nathan Friedman Fall, 2006.
Mathematics for Business and Economics - I
Chapter 1 Section 3 Copyright © 2011 Pearson Education, Inc.
Copyright © Cengage Learning. All rights reserved. Real Numbers and Their Basic Properties 1.
Section 3Chapter 1. 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Objectives Exponents, Roots, and Order of Operations Use exponents. Find.
Algebraic Expressions & Polynomials
Exponents.
P.1 Real Numbers and Algebraic Expressions. Negative numbers Units to the left of the origin are negative. Positive numbers Units to the right of the.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Thinking Mathematically
1 Operators and Expressions. Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators.
MM150 Unit 3 Seminar Agenda Seminar Topics Order of Operations Linear Equations in One Variable Formulas Applications of Linear Equations.
Real numbers In algebra, we work with the set of real numbers, which we can model using a number line. Real numbers describe real-world quantities such.
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
Topic 4 Real Numbers Rational Numbers To express a fraction as a decimal, divide the numerator by the denominator.
Prefix, Postfix and Infix. Infix notation  A-B/(C+D)  evaluate C+D (call the result X),  then B/X (call the result Y),  and finally A-Y.  The order.
Chapter 3 Arithmatic Operations 3.1 Operators An operator is a symbol or world that represents some operation that is performed on one or more data values.
Lecture III Start programming in Fortran Yi Lin Jan 11, 2007.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
CHAPTER 1 INTRODUCTION TO COMPUTING 1.1 Introduction.
FUNCTIONS IN FORTRAN For a complex program difficulties like writing it and debugging are encountered. These can be minimized by breaking main program.
Operators & Expressions
Copyright © 2011 Pearson Education, Inc. Polynomials CHAPTER 5.1Exponents and Scientific Notation 5.2Introduction to Polynomials 5.3Adding and Subtracting.
Operators and Expressions. Introduction C operators can be classified into a number of categories 1.Arithmetic(+, -, *, /, %) 2.Relational (, >=, ==,
Exponents. 1. Relate and apply the concept of exponents (incl. zero). 2. Perform calculations following proper order of operations. 3. Applying laws of.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
Math 094 Section 1.3 Exponents, Order of Operations, and Variable Expressions.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
Equivalent expressions are expressions that are the same, even though they may look a little different.
1 Chapter 3 – Operators and Expressions Outline 3.1Introduction 3.2Arithmetic operators 3.3Relational operators 3.4Logical operators 3.5Assignment operators.
Principles of Programming - NI July Chapter 4: Basic C Operators In this chapter, you will learn about: Assignment operators Arithmetic operators.
ALGEBRIC EQUATIONS UNIT 01 LESSON 02. OBJECTIVES Students will be able to: Apply the Algebraic expressions to simplify algebraic expressions. Produce.
Variables, Operators, and Expressions
Operators & Expressions
Topics Designing a Program Input, Processing, and Output
Operators and Expressions
INSPIRING CREATIVE AND INNOVATIVE MINDS
5.2 The Integers; Order of Operations
Arithmetic operations & assignment statement
Chapter 7 Objectives Define basic terms in algebra: integer, number statement, expression, and coefficient Learn the relationships between positive and.
MATLAB DENC 2533 ECADD LAB 9.
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Place Value, Names for Numbers, and Reading Tables
Chapter 1 Section 4.
Chapter-3 Operators.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
OPERATORS in C Programming
PRESENTED BY ADNAN M. UZAIR NOMAN
Rules of evaluation The value of a number is itself.
DATA TYPES AND OPERATIONS
ICS 101 Lab 3 Hossain Arif ICS Dept
OPERATORS in C Programming
Presentation transcript:

1 Arithmetic Expressions and Built in Functions 1.ARITHMETIC OPERATORS There are five basic arithmetic operations with Fortran. These are given in the following Table 1 Table 1 Arithmetic operations with FORTRAN Algebraic SymbolFortran SymbolMeaning ++Addition --Subtraction *Multiplication /Division AbAb **Exponentiation

2 2. ARITHMETIC EXPRESSION Arithmetic expressions are formed either by combining integer variable names and constants with arithmetic operators or by combining real variable names and constants with arithmetic operators. Thus, in Fortran, two types of expressions are defined. i) Integer Expression e.g. I, L, +8, -7, N*M, M*N+I, (I*J) / (I+K)+I etc. ii) Real Expression e.g. A, -A, 4.2, 1.5, -A+B+C*D, (A+B), (A+4.5), (A*B) /(D*C) etc. Note:If expression consists of integer/real variables then it is called Mixed Mode expressione.g. 20+I+X**3, (A+B)* (K+J) etc.

3 3 (a)Integer arithmetic: If the operands are integers, then integer arithmetic is performed to yield an integer. e.g. 5+3yields8 5*3yields15 5-3yields 2 Integer division in FORTRAN, also yields an integer- the integral part of the quotient only i.e. the fractional part of the quotient is deleted in integer division. e.g. 5/4yields1 4/5yields0 -7/2yields-3 Exponent of integer number/variable can only be integer e.g I 2 =I** 2(Valid) =I**2.0(Invalid) 3(b)Real arithmetic : If the operands are real, the real arithmetic is performed to yield a real value. e.g yields *3. yields yields 2.0 etc.

4 Division by real arithmetic in FORTRAN is similar to ordinary division, e.g. 5.0/4.0 yields /5.0 yields 0.8 etc. Exponent of real number/variable can be integer/real. e.g. If we have expression, z = x y = x ** y, then it is solved as i) If y is real Taking log on both sides, log z = y log x Taking antilog, z = antilog (y log x) = e y log x = exp (y log x) ii) If y is an integer, then x ** y is evaluated by repeated multiplication. Now, if we want to solve (3.2) 7 then if we write, 3.2 ** 7.0, then log and antilog will be used by the computer. If we write, 3.2 ** 7, then simple multiplication will take place. Since, logs takes more computation time as compared to multiplication, hence exponent should be kept real only if it contains fractional part too, otherwise keep the exponent integer.

5 4. HIERARCHICAL RULE FOR THE OPERATONS IN THE EXPRESSIONS The order, in which arithmetic operations are executed in an expression, is called the hierarchy or precedence of operations. Table. 2 shows the precedence priority of operators.

6 Table 2 Precedence of Operators PriorityFortran SymbolMeaning/Operation 1.( )Parenthesis 2.**Exponentiation 3.*/Multiplication, Division 4.+-Addition, Subtraction

7 Rule 1. All expressions in parentheses are evaluated first. Rule 2.Operators in the same expression are evaluated according to the hierarchy : ** followed by *, / followed by +, -. Rule 3.If priority of two operators are equal, then expression is scanned from left to right whichever operator (of same priority) comes first will be operated first. Rule 4.Priority of operators can be changed by using parentheses.( Expression within parentheses is to be solved first by applying Rule 1 and Rule 2). Rule 5.Parentheses can be nested also. The inner most parentheses is to be solved first and then next outer and so on.

8 Example 1 Consider an expression X** 6+8.0* Y – Z/ (A-8.7) Following Hierarchical Rule, the solution will be in the steps shown

9 Example 2. Let us now consider the solution of an expression X * Y + Z/ (I+J) – (I** (J/4)) where X,Y and Z are real variables and I and J are integer variables. This expression is evaluated in following steps with mixed mode as shown below.

10 Example 3. The expression x + y/ (Z*A+B**2) is evaluated as follows, x + y / /(Z*AB**2) +

11 Note: Parenthesis can be used to make the expression more clear. By using the parenthesis we can alter the precedence of operation e.g. in b+4*a / b + a the precedence is : but in the expression, b+4*a / (b + a) the precedence (of (b+a)) changes as shown below:

12 e.g (i) The expression, A B + is written as, A ** B + (C/D)* G+A/(5*B**3) (ii) The expression, is written as, A/(B*C) – D**2

13 5.BUILT IN FUNCTIONS Built in functions are also known as LIBRARY FUNCTIONS OR INTRINSIC FUNCTIONS. These are the pre-written programs by the manufacturer of the compiler, for commonly used mathematical functions. These functions can be called, in user’s program by writing the name of the function-program and enclosing the argument in the parentheses Example SQRT (X) =, ABS (X) = ALOG (X) = log e X etc. Points to Remember (while using Built-in-functions in the Program) The argument should be enclosed in parentheses. If a function has more than one argument, then arguments should be separated by commas. Care should be taken to match - the type - the number and - the order of arguments.. Most common functions used in FORTRAN have been summarized in Table 3.

14 Table 3. FunctionMathematical NotationFORTRAN Square root of xSQRT (X) Absolute value of xABS (X) Exponential of xexex EXP (X) Sine of xsin xSIN (X) Cosine of xcos xCOS (X) Tangent of xtan xTAN (X) Inverse of sinesin -1 xASIN (X) Inverse of cosinecos -1 xACOS (X) Inverse of tangenttan -1 xATAN (X) Log of xlog 10 xALOG 10(X) Natural log of xlog e xALOG (X) Convert integer Into realFLOAT (I) Truncate real x into integerI FIX (X) Give only quotientThese two functions areDIV (I,J) Give only remainderUsed only for integers.MOD (I,J)

15 e.g:- (i)an expressionis written as SQRT (SQRT ((A-B) / (C+4*D))) (ii)The expression is written as A ** (C-1) / ALOG (B) (iii)The expression tan -1 is written as ATAN (SQRT (Sin (ABS (A))**2)) iv)The exp e b tan 3 a is written as EXP (B) * TAN (A)**3.

16 6.EXECUTABLE AND NON-EXECUTABLE STATEMENTS Executable Statements: These are the statements which result in a machine code i.e. which result in some kind of machine-language instruction. For example, READ, WRITE, STOP, GOTO, IF, DO etc. Non-Executable Statement : These are the statements which do not result in any machine code i.e. which will not result in any machine-language instructions. For example COMMENT statements, TYPE statement, FORMAT, TYPE, END, ELSE, COMMON, DIMENSION etc. Note : STOP is an executable statement. Its machine – language equivalent stops the computer from executing the next machine – language instruction of the program. END is a non-executable statement. It tells the compiler that this is the end of the program and there are no more FORTRAN statements to be transferred into machine – language instructions.