Introduction to Matlab

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
CSE 123 Symbolic Processing. Declaring Symbolic Variables and Constants To enable symbolic processing, the variables and constants involved must first.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
Introduction to MATLAB
Lecture 16 Symbolic Mathematics Symbolic mathematics: algebraezplotcalculus © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
1 Data types, operations, and expressions Continued l Overview l Assignment statement l Increment and Decrement operators l Short hand operators l The.
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.
Builtin and user defined functions
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.
Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
Array Addition  Two arrays can be added if and only if both arrays have exactly the same dimensions.  Assuming the dimension requirement is satisfied,
Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 Djordje Gligorijevic, Temple University, Fall 2015.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Yasser F. O. Mohammad Approximations and Round-off Errors.
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.
Chapter 12 Review: Symbolic Mathematics
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Eng Ship Structures 1 Introduction to Matlab.
Lecture 1 - Introduction June 3, 2002 CVEN 302. Lecture’s Goals General Introduction to CVEN Computer Applications in Engineering and Construction.
Introduction To this point MATLAB has been used to answer questions with a numeric value ▫Variables are assigned specific values ▫Answers are numbers MATLAB.
Matlab The language of Technical computing Mr. D. Suresh Assistant Professor, Dept. of CSE, PSNA CET, Dindigul.
OUTLINE Overview Numbers, variables and similar in Matlab
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Matlab Tutorial (material available at 1 Dr. Jim Martin Associate Professor School of Computing.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Introduction to Matlab
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
September 15, 2005 Lecture 5 - By Paul Lin 1 CPET 190 Lecture 5 Problem Solving with MATLAB
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Spring 2016 Statics - TAM 210 & TAM 211 Discussion 1 - Intro to Matlab 1.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
MATLAB Constants, Variables & Expression Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
Matlab Tutorial (material available at 1 Dr. Jim Martin Associate Professor School of Computing.
Array and Matrix Operations EE 201 Fall  Achieve Comprehension LOL of Array and Matrix Operations. Class Learning Objectives 2.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1 Introduction to Matlab. 2 What is Matlab? Matlab is basically a high level language which has many specialized toolboxes for making things easier for.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Basic operations in Matlab EE 201.  Achieve Comprehension LOL of Matlab basic operations. Class Learning Objectives 2.
Simple C Programs.
Introduction To MATLAB
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
Built-in MATLAB Functions Chapter 3
BIL 104E Introduction to Scientific and Engineering Computing
Lecture: MATLAB Chapter 1 Introduction
Computer Simulation Lab
INTRODUCTION TO BASIC MATLAB
Matlab Workshop 9/22/2018.
Symbolic mathematics: algebra ezplot calculus
محاسبات عددی در مهندسی پزشکی جلسه اول و دوم مقدمه ای بر نرم افزار MATLAB گلناز بغدادی 1391.
Introduction to MATLAB [Vectors and Matrices] Lab 2
Fourth Year – Software Engineering
-seminar 1 for digital signal processing
Computer Simulation Lab
Introduction to Matlab
Presentation transcript:

Introduction to Matlab

What is Matlab? Matlab Assembly Matlab is basically a high level language which has many specialized toolboxes for making things easier for us. How high? Assembly High Level Languages such as C, Pascal etc. Matlab

Matlab Screen Command Window type commands Current Directory View folders and m-files Workspace View program variables Double click on a variable to see it in the Array Editor Command History view past commands

Variables No need for types. i.e., All variables are created with double precision unless specified and they are matrices. After these statements, the variables are 1x1 matrices with double precision int a; double b; float c; Example: >>x=5; >>x1=2;

Sym, syms, and vpa Sym Create the symbolic variables Ex: Syms x = sym('x'); y = sym('y','positive'); Syms Shortcut for creating symbolic variables and functions syms x y syms x y real *SYM and SYMS are essentially the same; SYMS is often used in the command form, while SYM is often used in the function form.

Vpa Variable-precision arithmetic Ex: >> vpa(pi) ans = 3.1415926535897932384626433832795 >> vpa(pi,4) 3.142

Exponential and Logarithmic exp(x) sqrt(x) Ex: >> y=exp(x) >> y=sqrt(x) Logarithmic log(x) natural logarithm ln log10(x) >> log10(x)= log(x) / log(10) log2(x) >> log2(x)=  log(x) / log(2)

ceil, and floor ceil(x) round to nearest integer towards + Ex: ans = 4 floor(x) round to nearest integer towards – >> floor(3.2) 3

Round and abs round(x) round to nearest integer Ex: >>round(2.4) ans= 2 >>round(2.6) 3 abs(x) absolute value >>abs(-5) 5

Trigonometric and their inverse cos(x) acos(x) sin(x) asin(x) tan(x) atan(x) cot(x) acot(x) csc(x) acsc(x) sec(x) asec(x) All trigonometric functions require the use of radians and not degrees degtorad Ex: >>x=degtorad(45) x = 0.7854 >> cos(x) ans = 0.7071 *Inverse of trigonometric returns real values in the interval [0,pi].

Array, Matrix a vector x = [1 2 5 1] 1 2 5 1 a matrix x = [1 2 3; 5 1 4; 3 2 -1] 1 2 3 5 1 4 3 2 -1 transpose y = x’ y = 1 2 5

Inverse x = [1 2; 5 1] Determinant x = [1 2; 5 1] y=inv(x) y = -0.1111 0.2222 0.5556 -0.1111 Determinant x = [1 2; 5 1] A=det(x) A = -9

t =1:10 t = 1 2 3 4 5 6 7 8 9 10 k =2:-0.5:-1 k = 2 1.5 1 0.5 0 -0.5 -1 B = [1:4; 5:8] x = 1 2 3 4 5 6 7 8

zeros(M,N) MxN matrix of zeros ones(M,N) MxN matrix of ones rand(M,N) MxN matrix of uniformly distributed random numbers on (0,1) x = zeros(1,3) x = 0 0 0 x = ones(1,3) 1 1 1 x = rand(1,3) 0.9501 0.2311 0.6068

Matrix Index The matrix indices begin from 1 (not 0 (as in C)) The matrix indices must be positive integer A(-2), A(0) Error: ??? Subscript indices must either be real positive integers or logicals. A(4,2) Error: ??? Index exceeds matrix dimensions.

x = [1 2], y = [4 5], z=[ 0 0] A = [ x y] 1 2 4 5 B = [x ; y] 1 2 4 5 1 2 4 5 B = [x ; y] 1 2 4 5 C = [x y ;z] Error: ??? Error using ==> vertcat CAT arguments dimensions are not consistent.

Operators (arithmetic) + addition - subtraction * multiplication / division ^ power

Given A and B: Addition Subtraction Product Transpose

Operators (Element by Element) .* element-by-element multiplication ./ element-by-element division .^ element-by-element power

A = [1 2 3; 5 1 4; 3 2 1] A = 1 2 3 5 1 4 3 2 -1 b = x .* y b= 3 8 -3 c = x . / y c= 0.33 0.5 -3 d = x .^2 d= 1 4 9 x = A(1,:) x= 1 2 3 y = A(3 ,:) y= 3 4 -1

Factor, Expand, and Simplify factor(f) >>syms x >>f=x^3-6*x^2+11*x-6; >>y=factor(f) y= (x-1)*(x-2)*(x-3) expand >> expand((x-1)*(x-2)) ans = x^2 - 3*x + 2

simplify Algebraic simplification >>syms x >>f1=sin(x)^2 + cos(x)^2 +log(x); >> simplify(f1) ans= 1+log(x)

Solve and dsolve solve Solve equations and systems >>syms x >>solve(x^2-3*x+2) ans = 1 2

>>S = solve('x + y = 1','x - 11*y = 5') S = x: [1x1 sym] >>syms x y >>S = solve('x + y = 1','x - 11*y = 5') S = x: [1x1 sym] y: [1x1 sym] >>S = [S.x S.y] [ 4/3, -1/3]

dsolve Ordinary differential equation >>dsolve('Dx = -a*x') ans = C2*exp(-a*t)

Differentiation and Integration Differences and approximate derivatives >> x=[2 5 9 1 3]; >> diff(x) ans = 3 4 -8 2 >> diff(sym('x^3+2*x^2-x+1')) 3*x^2 + 4*x - 1

int Integrate symbolic expression >>int(sym('x')) ans = x^2/2

limit Compute limit of symbolic expression >>syms x >>limit(sin(x)/x) ans= 1

Sum of series Symsum Sum of series S= 1+2^2+3^2+…+n^2 = >>syms k >>symsum(k^2, 1, 10) ans = 385

Questions ?