MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

Similar documents
Arithmetic and Logic Blocks

Script started on Thu 25 Aug :00:40 PM CDT

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5.

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Lecturer: Keyvan Dehmamy

Finding, Starting and Using Matlab

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Dr Richard Greenaway

Introduction to GNU-Octave

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

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

A General Introduction to Matlab

Built-in Types of Data

Lecture 1: What is MATLAB?

Dr Richard Greenaway

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Consider this m file that creates a file that you can load data into called rain.txt

Introduction to Engineering gii

Basic types and definitions. Chapter 3 of Thompson

Introduction to MATLAB Programming

A QUICK INTRODUCTION TO MATLAB

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

A very brief Matlab introduction

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

LAB 1 General MATLAB Information 1

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks

A Guide to Using Some Basic MATLAB Functions

Math 2250 MATLAB TUTORIAL Fall 2005

MATH 5520 Basics of MATLAB

MATH 3511 Basics of MATLAB

Matlab Workshop I. Niloufer Mackey and Lixin Shen

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

ANSI C Programming Simple Programs

A GUIDE FOR USING MATLAB IN COMPUTER SCIENCE AND COMPUTER ENGINEERING TABLE OF CONTENTS

C Programs: Simple Statements and Expressions

GRAPH 4.4. Megha K. Raman APRIL 22, 2015

Ebooks Chemical Engineering

What did we talk about last time? Examples switch statements

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

How to Design Programs Languages

Chapter 2. MATLAB Basis

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Computer Programming in MATLAB

Chapter 1 MATLAB Preliminaries

Chapter 1 Introduction to MATLAB

Excel Tool: Calculations with Data Sets

Lecture 2 FORTRAN Basics. Lubna Ahmed

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

1001ICT Introduction To Programming Lecture Notes

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Computational Physics

Julia Calculator ( Introduction)

Single row numeric functions

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

General MATLAB Information 1

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

A. Matrix-wise and element-wise operations

DEPARTMENT OF MATHS, MJ COLLEGE

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

Some elements for Matlab programming

L-System Fractal Generator: Language Reference Manual

Subprograms. FORTRAN 77 Chapter 5. Subprograms. Subprograms. Subprograms. Function Subprograms 1/5/2014. Satish Chandra.

Functions. Systems Programming Concepts

Mentor Graphics Predefined Packages

SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK

Chapter 2. Outline. Simple C++ Programs

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

Outline. Data and Operations. Data Types. Integral Types

CSCE 110 PROGRAMMING FUNDAMENTALS

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Department of Computer Science

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

Chapter 3 - Functions

Fundamentals of MATLAB Usage

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Matlab Tutorial, CDS

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name]

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

A very short introduction to Matlab and Octave

Learning the Language - V

Using the um-fpu with the Javelin Stamp

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Data Types and Variables in C language

JUN / 04 VERSION 7.0

3+2 3*2 3/2 3^2 3**2 In matlab, use ^ or ** for exponentiation. In fortran, use only ** not ^ VARIABLES LECTURE 1: ARITHMETIC AND FUNCTIONS

I. Introduction to Programming Using MATLAB

An Introduction to MATLAB

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

Computing Fundamentals

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Course Outline. Introduction to java

ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I

MATLAB: a Brief Introduction. by Robert L. Rankin

Methods: A Deeper Look

Transcription:

MATLAB Constants, Variables & Expression

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.

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

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 1 2 a= 3 4 3x2 matrix 6 elements 5 6 b=[1 2 3 4] 1x4 array 4 elements, row vector c= 1 3 5 3x1 array 3 elements, column vector a(2,1)=3 b(3)=3 c(2)=3 Row 2 Column 1

In character set we have Character Set 1. Alphabets :A,B,C..Z & a,b,c z 2. Numerals :0,1,2,3,4,5,6,7,8,9 3. Special Characters :@, #, $, % 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 : int8 uint8 Integer Single means less space Double means more space Conversion- No of bits >>x=890.47637 Unsigned Integer >>y=int8(x); or y=single(x) or y= double(x) No of bits

Data Types cont Cell >>A=[1 2 3 4]; >>B=[2 3 1; 4 5 3; 5 7 3]; >>C=zeros(2,3,3); >>D_cell={A B C}; Accessing data >>D_cell{1} : used for storing dissimilar kinds of data i.e matrix A matrix B C= Three zero matrix of 2x3 each => 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 Function Handle :MATLAB provides interface to java programming language :Handle to MATLAB function, see feval for evaluating of function

Constants & Variables Constants: Fixed value 1. Numeric constant: i. Integer :234-233 23563 ii. Real :10.23419 0.0028938 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) >>x_rad=angle(x) >>y=conj(x); %magnitude of x %angle of 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. Note: >>x=22; >>y=45.67; % x is an integer variable %y is a float variable. MATLAB is case sensitive, n & N are different variables

Constants & Variables cont Special constant & Variables:

Operators 1. Arithmetic operator: let p=3, q=2 Operator Operation Algebraic form MATLAB form Result + Addition p+q p+q 5 - Subtraction p-q P-q 1 * Multiplication pxq p*q 6 / Division p/q p/q 1.5 \ Division p\q p\q 0.6667 ^ Exponentiation p q p^q 9

Operators cont Operator Operation Algebraic form.* Element by element multiplication./ Element by element right division.\ Element by element left division MATLAB form Result pxq p.*q 6 p/q p./q 1.5 p\q p.\q 0.6667.^ Element by element exponentiation p q p.^q 9 Example: Repeat above with p=[1 2; 3 4] & q=[1 2; 3 4] & check the results

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 = 0.1703 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 sinh asin asinh exp log log10 rand sqrt - Sine in degree - Hyperbolic sine. - Inverse sine. - Inverse hyperbolic sine. - Exponential. - Natural logarithm. - Common (base 10) logarithm. - to generate random numbers. - 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?