Introduction to Matlab. Entering Commands Constants and Functions >> pi ans = 3.1416 >> eps ans = 2.2204e-016 >> sin(pi/2) ans = 1 >> log(1000) ans =

Slides:



Advertisements
Similar presentations
Maths & Trig, Statistical functions. ABS Returns the absolute value of a number The absolute value of a number is the number without its sign Syntax ◦
Advertisements

The Inverse Trigonometric Functions Section 4.2. Objectives Find the exact value of expressions involving the inverse sine, cosine, and tangent functions.
TRIGONOMETRY OF RIGHT TRIANGLES. TRIGONOMETRIC RATIOS Consider a right triangle with as one of its acute angles. The trigonometric ratios are defined.
7.3 Trigonometric Functions of Angles. Angle in Standard Position Distance r from ( x, y ) to origin always (+) r ( x, y ) x y  y x.
Fall 2006AE6382 Design Computing1 Numeric Representation in a Computer Learning Objectives Understand how numbers are stored in a computer and how the.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
MATLAB Basics CS 111 Introduction to Computing in Engineering and Science.
Unit 34 TRIGONOMETRIC FUNCTIONS WITH RIGHT TRIANGLES.
Trigonometric Functions on Any Angle Section 4.4.
Inverse Hyperbolic Functions. The Inverse Hyperbolic Sine, Inverse Hyperbolic Cosine & Inverse Hyperbolic Tangent.
BIL101, Introduction to Computers and Information Systems Chapter 12 A Portable Scientific Visualization Program: GnuPlot Prepared by Metin Demiralp Istanbul.
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
ICS 103 Lab 2-Arithmetic Expressions. Lab Objectives Learn different arithmetic operators Learn different arithmetic operators Learn how to use arithmetic.
Section 4.6 Graphs of Other Trigonometric Functions.
1 Python Chapter 2 © Samuel Marateck, After you install the compiler, an icon labeled IDLE (Python GUI) will appear on the screen. If you click.
Introduction to MATLAB
Raptor Mr. Lau Ka Lun Lai King Catholic Secondary School.
1 Chapter 1 Preliminaries Functions and Their Graphs.
Computer Science 121 Scientific Computing Winter 2014 Chapter 3 Simple Types: Numbers, Text, Booleans.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (2): MATLAB Environment (Chapter 1)
PRACTICAL COMMON LISP Peter Seibel 1.
IMS 3253: Math 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Five Fundamental Math Operations Precedence of Math.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Computer Science 111 Fundamentals of Programming I Basic Program Elements.
Chapter 3 Expressions and Interactivity Department of Computer Science Missouri State Univeristy.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
13.7 (part 2) answers 34) y = cos (x – 1.5) 35) y = cos (x + 3/(2π)) 36) y = sin x –3π 37) 38) y = sin (x – 2) –4 39) y = cos (x +3) + π 40) y = sin (x.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
1 Math Expressions and Operators. 2 Some C++ Operators Precedence OperatorDescription Higher ( )Function call +Positive - Negative *Multiplication / Division.
Graphs of Other Trigonometric Functions
Graphs of the Trig Functions Objective To use the graphs of the trigonometric functions.
Introduction to Matlab By E. Noura Semary. Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic.
Visual Basic I Programming
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
MATLAB Lecture Two Tuesday 5 July Chapter 3.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans.
Section 7.2 Addition and Subtraction Formulas Objectives: To understand how to apply the addition and subtraction formulas.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Reviewing Trigonometry Angle Measure Quadrant Express as a function of a positive acute angle Evaluate Find the angle Mixed Problems.
Some Useful MATLAB Functions
ECE 1304 Introduction to Electrical and Computer Engineering
Arithmetic Operations
Working in MATLAB.
ECE 1304 Introduction to Electrical and Computer Engineering
Matlab Introduction.
BIL 104E Introduction to Scientific and Engineering Computing
Computer Simulation Lab
MATLAB DENC 2533 ECADD LAB 9.
Graphs of Other Trigonometric Functions 11-2
Introduction to MATLAB
Chapter 8: Trigonometric Functions And Applications
Introduction to MATLAB
Graphs of Other Trigonometric Functions 11-2
Introduction to Matlab
Elementary Programming (C++)
Graphs of Other Trigonometric Functions 11-2
Chapter 8: Trigonometric Functions And Applications
The Inverse Trigonometric Functions (Continued)
Graphs of Other Trigonometric Functions 14-2
CS 111 Introduction to Computing in Engineering and Science
Introduction to MATLAB
Computer Simulation Lab
Presentation transcript:

Introduction to Matlab

Entering Commands

Constants and Functions >> pi ans = >> eps ans = e-016 >> sin(pi/2) ans = 1 >> log(1000) ans = >> log10(1000) ans = 3

Some Constants bitmax: Largest usable positive integer eps: Smallest number that changes the value of 1 when added to it. realmin:Smallest usable positive real number realmax: Largest usable positive real number ans:Default variable names used for results i or j: sqrt(-1) inf : Stands for infinity, e.g., 1/0 NaN or nan :Stands for not a number, e.g., 0/0.

Constants … >> bitmax ans = e+015 >> eps ans = e-016 >> realmin ans = e-308 >> realmax ans = e+308 >> ans ans = e+308 >> i ans = i >> inf ans = Inf >> NaN ans = NaN

Elementary Math Functions >> help elfun Elementary math functions. Trigonometric. sin - Sine. sinh - Hyperbolic sine. asin - Inverse sine. asinh - Inverse hyperbolic sine. cos - Cosine. cosh - Hyperbolic cosine. acos - Inverse cosine. acosh - Inverse hyperbolic cosine. tan - Tangent. tanh - Hyperbolic tangent. atan - Inverse tangent. atan2 - Four quadrant inverse tangent. atanh - Inverse hyperbolic tangent. sec - Secant. sech - Hyperbolic secant. asec - Inverse secant. asech - Inverse hyperbolic secant. csc - Cosecant. csch - Hyperbolic cosecant. acsc - Inverse cosecant. acsch - Inverse hyperbolic cosecant. cot - Cotangent. coth - Hyperbolic cotangent. acot - Inverse cotangent. acoth - Inverse hyperbolic cotangent.

Elementary Math Functions Exponential. exp - Exponential (e^x). log - Natural logarithm. log10 - Common (base 10) logarithm. log2 - Base 2 logarithm and dissect floating point number. pow2 - Base 2 power and scale floating point number. realpow - Power that will error out on complex result. reallog - Natural logarithm of real number. realsqrt - Square root of number greater than or equal to zero. sqrt - Square root. nextpow2 - Next higher power of 2.

Exponential Function Examples >> exp(log(3)) ans = >> log(exp(3)) ans = 3 >> log2(32) ans = 5 >> log2(pow2(5)) ans = 5 >> nextpow2(27) ans = 5

Elementary Math Functions Complex. abs - Absolute value. angle - Phase angle. complex - Construct complex data from real and imaginary parts. conj - Complex conjugate. imag - Complex imaginary part. real - Complex real part. unwrap - Unwrap phase angle. isreal - True for real array. cplxpair - Sort numbers into complex conjugate pairs.

Elementary Math Functions Rounding and remainder. fix - Round towards zero. floor - Round towards minus infinity. ceil - Round towards plus infinity. round - Round towards nearest integer. mod - Modulus (signed remainder after division). rem - Remainder after division. sign - Signum.

Remainder Examples >> mod( 12,7) ans = 5 >> mod(-12, 7) ans = 2 >> rem(12,7) ans = 5 >> rem(-12, 7) ans = -5

Rounding Examples round(2.7)  3, round(2.3)  2 round(-2.7)  -3, round(-2.3)  -2 fix(2.3)  2, fix(2.7)  2 fix(-2.3)  -2, fix(-2.7)  -2 ceil(2.3)  3, ceil(2.7)  3 ceil(-2.3)  -2, ceil(-2.7)  -2 floor(2.3)  2, floor(2.7)  2 floor(-2.3)  -3, floor(-2.7)  -3

Getting Help >> cotangent(pi/2) ??? Undefined function or variable 'cotangent'. >> help cotangent cotangent.m not found. >> lookfor cotangent ACOT Inverse cotangent. ACOTH Inverse hyperbolic cotangent. COT Cotangent. COTH Hyperbolic cotangent. ACOT Symbolic inverse cotangent. ACOTH Symbolic inverse hyperbolic cotangent. COT Symbolic cotangent. COTH Symbolic hyperbolic cotangent. >> help cot COT Cotangent. COT(X) is the cotangent of the elements of X.

Variables Let’s evaluate the following expression in matlab : Now let’s do the following: What if we need to evaluate the same expression for 2.1, 2.2, 2.3, … and lots of other values?

Variables Lets evaluate: It looks like the term appears 3 times in our expression. It would be nice if we evaluated it once and “remembered” the result for other occurrences of the term in the formula.

Variables Variables are named memory locations that can be assigned a value by the user or programmer The system can retrieve, or “remember” the value of a variable. Variables typically reside in main memory.

Variable Examples >> a ??? Undefined function or variable 'a'. >> a=2 a = 2 >> a+3 ans = 5 >> sqrt(a+14) ans = 4 >> a=a+12 a = 14

Variables Given: Rather than : >>cot(3)*sqrt(log(3)^3) + cos(3)*sin(log(3)), >>cot(2.7)*sqrt(log(2.7)^3) + cos(2.7)*sin(log(2.7)), … Use a variable: >>x=3 >>cot(x)*sqrt(log(x)^3) + cos(x)*sin(log(x)) >>x=2.7 >>cot(x)*sqrt(log(x)^3) + cos(x)*sin(log(x))

Variables Rather than evaluating : >> x=0.5 x = >> term=sin(x)+cos(x)^2 term = >> log(term) + realpow(term, 0.25) - term^2 ans =

Who and Clear >> who Your variables are: a ans term x >> whos Name Size Bytes Class a 1x1 8 double array ans 1x1 8 double array term 1x1 8 double array x 1x1 8 double array Grand total is 4 elements using 32 bytes >> clear a >> who Your variables are: ans term x >> clear >> who >>

Variable Names Only first 31 characters significant Matlab variables case sensitive Use meaningful names rather than shorter ones ! Avoid using existing function names !

Variable Name Examples >> log(5) ans = >> log = 4 log = 4 >> log(5) ??? Index exceeds matrix dimensions. >> clear log >> log(5) ans = >> Abc=123 Abc = 123 >> ABc ??? Undefined function or variable 'ABc'.

Getting User Input >> age=input('Please enter your age : ') Please enter your age : 29 age = 29 >> age + 2 ans = 31

String variables >> a = 'This is a string' a =This is a string >> b= 'Another string' b =Another string >> a + b ??? Error using ==> + Array dimensions must match for binary array op. >> whos Name Size Bytes Class a 1x16 32 char array b 1x14 28 char array Grand total is 30 elements using 60 bytes >> c = [a b 'Yet another string'] c =This is a stringAnother stringYet another string

String variables Variables can change types based on the values assigned to them : >> a a =This is a string >> a=3; >> whos Name Size Bytes Class a 1x1 8 double array b 1x14 28 char array c 1x48 96 char array Grand total is 63 elements using 132 bytes

Converting Numbers to Strings You can use the function num2str and int2str: >> s = 'The number ' + 3 s = >> s = ['The number ' 3] s =The number >> s = ['The number ' num2str(3)] s =The number 3 >> int2str(2.3) ans =2

Converting Strings to Numbers >> x = ['123' '789'] x = >> x2 = str2num(x) x2 = >> x2 + 1 ans = >> str2int('1.2') ??? Undefined function or variable 'str2int'.

Display Format The values displayed at the screen doesn’t necessarily include all the information. It is possible to change the display format. >> ans = e+019 >> format long >> ans = e+019

Operator Precedence 1 The contents of all bracketed expressions are evaluated, starting from the innermost brackets and working out. 2 All exponentials are evaluated, working from left to right. 3 All multiplications and divisions are evaluated, working from left to right. 4 All additions and subtractions are evaluated, working from left to right.

Operator Precedence >> * 4 ans = 14 >> 2 * 3 ^ 2 ans = 18 >> (2 + 3) * 4 ans = 20 >> (2^(2 + 3)) * 4 ans = 128