1 / 19

An Introduction to MATLAB

An Introduction to MATLAB. ELG3506 . What is MATLAB ?. The name MATLAB is an abbreviation for MATrix LABoratory. In its early years (1970), MATLAB was a matrix-based program for scientific and engineering calculations.

keira
Download Presentation

An Introduction to MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. An Introduction to MATLAB ELG3506

  2. What is MATLAB ? • The name MATLAB is an abbreviation for MATrix LABoratory. • In its early years (1970), MATLAB was a matrix-based program for scientific and engineering calculations. • Today, MATLAB is much more than a matrix-based program. It is a powerful computer program for doing numerical computations with vectors and arrays.

  3. What is MATLAB ? (Cont’d) • It is both an environment and a programming language, which gives it its great strength. • MATLAB is also very useful for representing information and data graphically in 2D and 3D. • MATLAB has many toolboxes, which are a collection of useful functions for specific classes of problems. Some of these toolboxes are: controls, signal processing and image processing, radio frequency, filter design just to name a few.

  4. The MATLAB Interface • There are two important windows on the MATLAB interface, • The “Command Window”, where you enter the command at the prompt (>>) and, • The “Workspace”, where all variables, arrays, matrices and vectors are temporally saved. • Programs or scripts can also be written and executed in a single file called “M-File”.

  5. The MATLAB Interface (Cont’d)

  6. The M-File * Adding a semi-colon at the end of a command, tells MATLAB not to print the results of the operations to the command screen.

  7. The M-File (Cont’d) To open the editor and create a new M-File, select, The File Menu New M-File

  8. MATLAB Syntax* Variables Variables are defined with the assignment operator, “=“. Values can come from constants, from computation involving values of other variables, or from the output of a function. For example: * Some content taken from Wikipedia (http://en.wikipedia.org/wiki/MATLAB)

  9. MATLAB Syntax (Cont’d) Vectors / Matrices In MATLAB, a vector refers to a one dimensional (1×N or N×1) matrix. A matrix generally refers to a multi-dimensional matrix, that is, a matrix with more than one dimension, for instance, an N×M, an N×M×L, etc., where N, M, and L are greater than 1.

  10. Basic Scalar Arithmetic • The basic arithmetic operators applied to scalars are +, -, * (multiplication), / (division) & ^ for powers. Where the constant ‘pi’ is equal to 3.1416’

  11. Matrix, Vector and Array Arithmetic • The Operators are +, -, *, /, ^, and ' . • MATLAB has two different types of arithmetic operations. • Matrix arithmetic operations are defined by the rules of linear algebra. • Array arithmetic operations are carried out element by element, and can be used with multidimensional arrays. • The period character (.) distinguishes the array operations from the matrix operations. • However, since the matrix and array operations are the same for addition and subtraction, the character pairs .+ and .- are not used.

  12. Matrix, Vector and Array Arithmetic

  13. Defining a Complex Number >> z = a + bi or, >> z = a + bj or, >> z = a + i*b or, >> z = complex(a,b) or, >> z = Aexp(j*B) or, >> z = a + b*sqrt(-1) Note: ‘i’ and ‘j’ must not be defined otherwise

  14. Iteration Statements(The ‘for’ and ‘while’ Loops) For Loop for j=1:4, statements end While Loop while n <= M statements end Condition Index

  15. Some Built-In Functions pi 3.1415.... zeros(n,m) n×m matrix of zeros eye(m) m×m identity matrix ones(n,m) n×m matrix of ones abs(z) absolute value of ‘z’ angle(z) angle of ‘z’ sqrt(x) square root, e.g. i=sqrt(-1) real(z), imag(z) real, imaginary parts of ‘z’ conj(z) complex conjugate of ‘z’ sin(x), cos(x), tan(x) trigonometric functions asin(y),acos(y), atan(y) inverse trigonometric functions sinh(x), cosh(x), tanh(x) hyperbolic functions exp(z) exponential function log(x) natural logarithm complex(a,b) define complex number a+jb

  16. Graphics in MATLAB plot(x,y) linear plot of y versus x grid on / off turns grid lines on graphics screen on or off title(’text’) prints a title for the plot xlabel(’text’) prints a label for the x-axis ylabel(’text’) prints a label for the y-axis axis([0, 1, -2, 2]) overrides' default limits for plotting hold on superimpose all subsequent plots hold off turns off a previous hold on legend(‘data1’,’data2’) include a legend for each data set clf clear graphics screen

  17. Graphics in MATLAB

  18. Example 1 The following MATLAB code plots the incident, reflected and standing waves on a transmission line for any reflection coefficient, Gamma.

More Related