MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.

Slides:



Advertisements
Similar presentations
ES 314 Lecture 2 Sep 1 Summary of lecture 1: course overview intro to matlab sections of Chapters 2 and 3.
Advertisements

IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Introduction to Matlab. I use Matlab for: Data analysis Data plotting Image Analysis Also – Simulations (solving odes/pdes/finite element methods) – Minimisations,
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
1 Fundamental Data types Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions l Assignment statement l Increment.
MATLAB Basics CS 111 Introduction to Computing in Engineering and Science.
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.
JavaScript, Third Edition
Fall 2006AE6382 Design Computing1 Relational and Logical Operators Use relational operators to test two values Work with values of true and false Compare.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Introduction to Matlab. Entering Commands Constants and Functions >> pi ans = >> eps ans = e-016 >> sin(pi/2) ans = 1 >> log(1000) ans =
Introduction to MATLAB
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Shell Scripting Awk (part1) Awk Programming Language standard unix language that is geared for text processing and creating formatted reports but it.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (2): MATLAB Environment (Chapter 1)
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
IMS 3253: Math 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Five Fundamental Math Operations Precedence of Math.
COMP 116: Introduction to Scientific Programming Lecture 28: Data types.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
Fortran: Expressions and Assignments Session Two ICoCSIS.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
MATLAB Trigonometry, Complex Numbers and Array Operations.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Introduction to Matlab
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
MA/CS 375 Fall 2002 Lecture 3. Example 2 A is a matrix with 3 rows and 2 columns.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Department of Electrical and Computer Engineering Introduction to C++: Primitive Data Types, Libraries and Operations By Hector M Lugo-Cordero August 27,
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
MA/CS 375 Fall 2003 Lecture 3. .* Multiplication We can use the.* operator to perform multiplication entry by entry of two matrices:
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
MA/CS 375 Fall 2002 Lecture 2. Motivation for Suffering All This Math and Stuff Try the Actor demo from
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Matlab Tutorial Iman Moazzen First Session – September 11, 2013.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Relational and Logical Operators EE 201 1C7-2 Spring 2012.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Chapter INTRODUCTION Data Types and Arithmetic Calculations.
Variables, Operators, and Expressions
ECE 1304 Introduction to Electrical and Computer Engineering
Numeric, Cell and Structural Arrays One of the strenghts of MATLAB is the capabilty to handle collection of numbers called ARRAYS. MATLAB refers to scalars,
ECE 1304 Introduction to Electrical and Computer Engineering
BIL 104E Introduction to Scientific and Engineering Computing
Data Types, Identifiers, and Expressions
Other Kinds of Arrays Chapter 11
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Arrays, For loop While loop Do while loop
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to C++ Programming
Introduction to MATLAB
Introduction to MATLAB [Vectors and Matrices] Lab 2
Introduction to Matlab
INTRODUCTION TO MATLAB
CS 111 Introduction to Computing in Engineering and Science
Introduction to MATLAB
Arrays in Matlab UC Berkeley Fall 2004, E Copyright 2005, Andy Packard
Presentation transcript:

MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun

Introduction  MATLAB can be used as a powerful programming language.  It do have IF, WHILE, FOR lops similar to other programming languages.  It has its own vocabulary and grammar.  All MATLAB in line commands can be used in M-files.

3 Variables and Arrays Array : A collection of data values organized into rows and columns, and known by a single name. Row 1 Row 2 Row 3 Row 4 Col 1Col 2Col 3Col 4Col 5 arr(3,2)

Variables and Arrays cont… Arrays The fundamental unit of data in MATLAB Scalars are also treated as arrays by MATLAB (1 row and 1 column). Row and column indices of an array start from 1. Arrays can be classified as vectors and matrices.

Variables and Arrays cont… Vector: Array with one dimension Matrix: Array with more than one dimension Size of an array is specified by the number of rows and the number of columns, with the number of rows mentioned first ( For example: n x m array ). Total number of elements in an array is the product of the number of rows and the number of columns.

Variables and Arrays cont… a=3x2 matrix  6 elements b=[ ]1x4 array  4 elements, row vector c= x1 array  3 elements, column vector a(2,1)=3b(3)=3c(2)=3 Row 2Column 1

Character Set In character set we have 1.Alphabets:A,B,C…..Z & a,b,c…z 2.Numerals:0,1,2,3,4,5,6,7,8,9 3.Special #, $, % etc 4.White Space :

Data Types There are 14 fundamental data types in MATLAB Default Numeric Data Type - double

Data Types cont… Note: –Sparse: Most of the element in the array are equal to zero, that is the array contains very few non zero elements. So it is not advisable to store all the elements. To reserve memory space and increase the computation speed, only non-zero elements and their indices are stored. Such format is called sparse. –Full: All elements and their indices are stored.

Data Types cont… Logical :True or False i.e >>a=40>50 =>a=0 Char : >>a=‘hello’ or a=‘Hello how are you’ So char is a 1-by-n array of character Numerical: Single means less space Double means more space Conversion->>x= >>y=int8(x); or y=single(x) or y= double(x) Integer No of bits int8 Unsigned Integer No of bits uint8

Data Types cont… Cell : used for storing dissimilar kinds of data i.e >>A=[ ];matrix A >>B=[2 3 1; 4 5 3; 5 7 3];matrix B >>C=zeros(2,3,3);C= Three zero matrix of 2x3 each >>D_cell={A B C}; Accessing data >>D_cell{1} => matrix A Structure: similar to cell but here data is stored in named field rather than cells. i.e. >> abc.name=‘Ram Kumar Verma’; >>abc.age=20; >>abc.sex=‘male’;

Data Types cont… Java Classes: MATLAB provides interface to java programming language Function Handle: Handle to MATLAB function, see “feval” for evaluating of function

Constants & Variables Constants: Fixed value 1.Numeric constant: i.Integer: ii.Real : iii.Complex :3+j*5-45+j*55.12(i or j both valid) Try it >>x=56.4-j*33.67; >>x_real=real(x); >>x_imag=imag(x); >>x_mag=abs(x)%magnitude of x >>x_rad=angle(x)%angle of x >>y=conj(x);%y=conjugate of x

Constants & Variables cont… >>[theta, r]=cart2pol(x,y) % cartesian coordinate x & y into polar coordinate theta & r, similarly reverse of it >>[x, y]=pol2cart(theta,r) 2.Character constant: i.Single character constant:‘A’, ‘g’, ’1’, ’ ‘ ii.String constant:‘Hello’, ‘19738’, ‘How is 3G’ iii.Space sequence constant: ‘\t’ => tab, ‘\n’ => new line

Constants & Variables cont… Variables: Variable starts with an alphabet followed by a number of alphabets or numerals or an underscore. Some valid variables names are name, x, sex, polynomial_degree, p12 etc. MATLAB does not require any variable or constant to be declared in advance at the start of a program. Variables can be defined at any step in the M-file by simply assigning values to them and the types of data assigned to the variable determines the type of variable. >>x=22;% x is an integer variable >>y=45.67;%y is a float variable. Note:MATLAB is case sensitive, n & N are different variables

Constants & Variables cont… Special constant & Variables:

Operators 1.Arithmetic operator: let p=3, q=2 OperatorOperationAlgebraic form MATLAB form Result +Additionp+q 5 -Subtractionp-qP-q1 *Multiplicationpxqp*q6 /Divisionp/q 1.5 \Divisionp\q ^Exponentiationpqpq p.^q9

Operators cont… Example : Repeat above with p=[1 2; 3 4] & q=[1 2; 3 4] & check the results OperatorOperationAlgebraic form MATLAB form Result.*Element by element multiplication pxqp.*q6./Element by element right division p/qp./q1.5.\Element by element left division p\qp.\q ^Element by element exponentiation pqpq p.^q9

Operators cont… 2.Relational operator

Operators cont… 3.Logical operator:

Hierarchy of operations Oder in which the arithmetic operations are executed, and the hierarchy is 1.Parentheses starting from innermost 2.Transpose, Power 3.Unary + (+A),Unary – (-A), Logical NOT(~) 4.Multiplication, Division 5.Addition, subtraction 6.Colon operator (:) 7.Realtional operators (<,<= etc) 8.Logical AND (&) 9.Logical OR (|)

Hierarchy of operations cont… Example: if i=2,j=3,k=4 & l=5, evaluate i.i*j+k*l ii.i*(j+K)*l iii.(i*j)+(k/l) iv.(i+j)*i^j

Built-in function >>x=15.5,y=2.45,z=4.5 >>a=log(sqrt(x/(y*z))) a = Here log => log e () & sqrt() are two built in functions. Syntax of built in fucntion function_name(variable_name or expression)

Built-in function sin - Sine in radian sind - Sine in degree sinh - Hyperbolic sine. asin - Inverse sine. asinh - Inverse hyperbolic sine. exp - Exponential. log - Natural logarithm. log10 - Common (base 10) logarithm. rand - to generate random numbers. sqrt - Square root. 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. Etc…………… a lots of functions are available

List of some commands Abs :Returns absolute number. In case of complex no returns magnitude Any :Returns True if any element of vector is non zero Angle :Returns phase angle in radians All :Returns true if all element of vector are non-zero Atan2 :Give tangent inverse Cart2pol:Convert cartesian to polar cordinates Pol2cart :Converts polar to cartesian coordinates Conj :Gives congugate of a complex number Factorial :Gives factorial of a number Imag :Returns imaginary part of a complex number Real :Return real part of complex number Etc………

Questions?