Basic operations in Matlab EE 201.  Achieve Comprehension LOL of Matlab basic operations. Class Learning Objectives 2.

Slides:



Advertisements
Similar presentations
7.1Variable Notation.
Advertisements

1 Chapter 2 Basic Elements of Fortran Programming.
Programming in Visual Basic
Introduction to MATLAB 7 for Engineers
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
JavaScript, Third Edition
1 BIL106E Introduction to Scientific & Engineering Computing Organizational matters Fortran 90 ( subset F ): Basics Example programs in detail.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
JavaScript – Part II Data Types and Operations George Mason University June 3, 2010.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
Release Numbers MATLAB is updated regularly The Mathworks packages their software in groups, called releases, New releases are issued twice a year in the.
ORDER OF OPERATIONS x 2 Evaluate the following arithmetic expression: x 2 Each student interpreted the problem differently, resulting in.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 1.
Input, Output, and Processing
1 Week 2 n Organizational matters n Fortran 90 (subset F): Basics n Example programs in detail.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Introduction to Matlab
1 Week 1: Variables, assignment, expressions READING: 1.2 – 1.4.
EGR 115 Introduction to Computing for Engineers Introduction to MATLAB Friday 29 August 2014 EGR 115 Introduction to Computing for Engineers.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
C++ for Engineers and Scientists Second Edition
29 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
 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.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology Taxila.
Chapter 02 (Part II) Introduction to C++ Programming.
 1) -5+6  2) 7+ (-8)  3)  4) 8(-3)  5) -9(2)  6) 18/2  7 (-9)/3 1 Algebra II.
Variables, Operators, and Expressions
Today Variable declaration Mathematical Operators Input and Output Lab
ECE 1304 Introduction to Electrical and Computer Engineering
Arithmetic Operations
Topics Designing a Program Input, Processing, and Output
ARITHMETIC IN C Operators.
ECE 1304 Introduction to Electrical and Computer Engineering
BASIC ELEMENTS OF A COMPUTER PROGRAM
BIL 104E Introduction to Scientific and Engineering Computing
Variables, Expressions, and IO
Introduction to Algebra
Introduction to Programming
MATLAB DENC 2533 ECADD LAB 9.
Data Types, Identifiers, and Expressions
Introduction to C++ Programming
Fourth Year – Software Engineering
Core Objects, Variables, Input, and Output
Elementary Programming (C++)
A mathematical phase containing numbers.
Topics Designing a Program Input, Processing, and Output
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
A mathematical phase containing numbers.
Experiment No. (1) - an introduction to MATLAB
Topics Designing a Program Input, Processing, and Output
Introduction to MATLAB
Presentation transcript:

Basic operations in Matlab EE 201

 Achieve Comprehension LOL of Matlab basic operations. Class Learning Objectives 2

Scalar Arithmetic Operations Name of operation Operation in Calculus Operation in MATLAB Symbol Multiplication ab ( a × b)a*b* Right division ( a ÷ b )a/b/ Additiona+b + Subtractiona-b - exponentiationabab a^b^ Power of 1010 x 1exe 3

Examples: 1) Write MATLAB expressions for the following algebraic expression 4

Solution: y=2*x+5*z^ OR y=2*x+5*z^0.5-4e2 OR y=2*x+5*z^0.5-4*10^2 5

Example : NumberExponent form MATLAB form × e × e-4 44×10 0 4e × e11 6

Order of precedence Operation FirstParentheses (), evaluated starting with the innermost pair. SecondExponentiation (power ) ^, evaluated from left to right. ThirdMultiplication * and division / with equal precedence, evaluated from left to right. FourthAddition + and subtraction - with equal precedence, evaluated from left to right. 7

Example  State the order of evaluation of the operators in each of the following MATLAB statement and show the value of x after statement is performed x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 4-1 ) ) ) ) ? 8

 Solution: 1) x = ( 3 * 9 * ( 3 + ( 9 * 3 / ( 4-1 ) ) ) ) 2) x = ( 3 * 9 * ( 3 + ( 9 * 3 / 3 ) ) ) 3) x = ( 3 * 9 * ( 3 + ( 27 / 3 ) ) ) 4) x = ( 3 * 9 * ( ) ) 5) x = ( 3 * 9 * 12 ) 6) x = ( 27 * 12) 7) x=324 9

The Assignment Operator (Replacement)=  When you type x=3 in MATLAB, you tell MATLAB to assign the value 3 to the variable x.  We can then type x = x + 2 in MATLAB. This assigns the value = 5 to x. But in algebra this implies that 0 = 2 ?!!!.  In algebra we can write x + 2 = 20, but in MATLAB we cannot ?!!!.  In MATLAB the left side of the = operator must be a single variable.  The right side must be a computable value. z+5=y wrong y=3; z=5+y correct 10

Variable Names  Variables are symbolic names that represent locations in the computer’s random access memory (RAM)  To use a variables must declare it by telling the compiler its name and value. This is called a variable declaration.  Variable declaration tells the compiler to allocate appropriate memory space for the variables. 11

Variable Names  Rules for declaring a variables in MATLAB: a-Variable names must begin with a letter b-The rest of name can contain letters, digits and underscore characters c-MATLAB is case-sensitive  Thus the following names represent 4 different variables: speed Speed SPEED Speed_1 d-Variables names must contain less than 63 characters 12

Note: Avoid Using Function Names for Variables  When naming a variable, make sure you are not using a name that is already used as a function name, either one of your own M-file functions or one of the functions (Command) in the MATLAB language. If you define a variable with a function name, you will not be able to call that function until you remove the variable from memory with the clear function,clear  For example, if you enter the following command, you will not be able to use the MATLAB help command until you clear the variable with clear help`  help = 50; 13

14

Example  which of the following are legitimate (valid) variable names in MATLAB? Explain why invalid? a Global b My_var c _input d X+Y e Example1-1 15

 Answer: a-legitimate (valid) b-legitimate (valid) c-invalid because begins with a underscore d-invalid because contains symbol + e-invalid because contains symbol – 16

Special Variables and Constants CommandDescription ansTemporary variable containing the most recent answer. piThe number π= InfInfinity ( ∞ ) (example: 7/0). NaNIndicates an undefined numerical result (Not a Number), (example: 0/0). 17

Some Commonly Used Mathematical Functions Function in calculusMATLAB Syntax exex exp(x) sqrt(x) In xlog(x) log 10 xlog10(x) abs(x) cos xcos(x) sin xsin(x) tan xtan(x) cos -1 xacos(x) sin -1 xasin(x) tan -1 xatan(x) Note: The MATLAB trigonometric functions use radian measure To convert from Degree → Radian use : 180º → π Or use sind( ) 18

Examples Write MATLAB expressions to calculate the following algebraic expressions: a- b- y= cos ( ) sin(90º) 19

Solution: a- x=exp((-2.1)^3) +3.47*log10(14)+(287)^(1/4) b- y=cos(((4.12*pi)/6)^2)+100*sin(pi/2) 20

Expressing Function Arguments We can write sin 2 in text,but MATLAB requires parentheses surrounding the 2 (which is called the function argument or parameter) Thus to evaluate sin 2 in MATLAB, we type sin(2).The MATLAB function name must be followed by a pair of parentheses that surround the argument. Example : y=sinx 2 y=sin(x^2) w=sin 2 x w=(sin (x))^2 or w= sin(x)^2 z=sin(sqrt (x)+1) 21

22 Some common mathematical functions ceil(x) fix(x) floor(x) round(x) sign(x) Round to nearest integer toward ∞. Round to nearest integer toward zero. Round to nearest integer toward -∞. Round toward nearest integer. +1 if x > 0;0 if x=0;-1 if x<0

Example: 23

Complex numbers or 4. The solution 1. (3+6i)*(-7-9i) or (3+6*i)*(-7- 9*i) 2. (5+4i)/(5-4i) or (5+4*i)/(5-4*i) 3. 3/2*i or 3i/2 4. 3/(2*i) or 3/2i 24

Complex Numbers (continue) note that i should not be defined as a variable,if so then don’t give * before i. for example if you define i=5 then 3+6i will be written as 3+6i (not 3+6*i). 25