Experiment 2: Introduction to MATLAB II

Similar documents
SIGNALS AND LINEAR SYSTEMS LABORATORY EELE Experiment (2) Introduction to MATLAB - Part (2) Prepared by:

Representing Polynomials

The roots are found with the following two statements. We have denoted the polynomial as p1, and the roots as roots_ p1.

12. Homogeneous Linear Systems of ODEs

Linear Algebra review Powers of a diagonalizable matrix Spectral decomposition

MAT 275 Laboratory 7 Laplace Transform and the Symbolic Math Toolbox

Linear Algebra review Powers of a diagonalizable matrix Spectral decomposition

Lecture 7 Symbolic Computations

Control System Engineering

June 2011 PURDUE UNIVERSITY Study Guide for the Credit Exam in (MA 262) Linear Algebra and Differential Equations

MATLAB BASICS. Instructor: Prof. Shahrouk Ahmadi. TA: Kartik Bulusu

Chap 3. Linear Algebra

3. Array and Matrix Operations

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

AMS 27L LAB #6 Winter 2009

x x2 2 + x3 3 x4 3. Use the divided-difference method to find a polynomial of least degree that fits the values shown: (b)

Linear Algebra Practice Problems

HANDOUT E.22 - EXAMPLES ON STABILITY ANALYSIS

Taylor and Maclaurin Series. Copyright Cengage Learning. All rights reserved.

Some suggested repetition for the course MAA508

Applied Linear Algebra in Geoscience Using MATLAB

Using MATLAB. Linear Algebra

Properties of Linear Transformations from R n to R m

Linear Algebra: Matrix Eigenvalue Problems

Math 3313: Differential Equations Second-order ordinary differential equations

Logarithmic and Exponential Equations and Change-of-Base

Math 104: l Hospital s rule, Differential Equations and Integration

Taylor and Maclaurin Series. Approximating functions using Polynomials.

INTRODUCTION TO TRANSFER FUNCTIONS

Applied Linear Algebra in Geoscience Using MATLAB

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,

MATLAB Lecture 7 Calculus 微积分

Chapter #4 EEE8086-EEE8115. Robust and Adaptive Control Systems

Additional Homework Problems

2.3. VECTOR SPACES 25

Eigenvalues and Eigenvectors

Matlab Exercise 0 Due 1/25/06

A matrix is a rectangular array of. objects arranged in rows and columns. The objects are called the entries. is called the size of the matrix, and

Definition (T -invariant subspace) Example. Example

Advanced Engineering Mathematics Prof. Pratima Panigrahi Department of Mathematics Indian Institute of Technology, Kharagpur

Chapter 1 Vector Spaces

5.) For each of the given sets of vectors, determine whether or not the set spans R 3. Give reasons for your answers.

A matrix is a rectangular array of. objects arranged in rows and columns. The objects are called the entries. is called the size of the matrix, and

MATH 223 FINAL EXAM APRIL, 2005

Algebraic Properties of Solutions of Linear Systems

Math 322. Spring 2015 Review Problems for Midterm 2

Math 217: Eigenspaces and Characteristic Polynomials Professor Karen Smith

Section 5.8. Taylor Series

REVIEW OF DIFFERENTIAL CALCULUS

Lecture 4: Matrices. Math 98, Spring Math 98, Spring 2018 Lecture 4: Matrices 1 / 20

Math 307 Learning Goals. March 23, 2010

MATH 320: PRACTICE PROBLEMS FOR THE FINAL AND SOLUTIONS

YORK UNIVERSITY. Faculty of Science Department of Mathematics and Statistics MATH M Test #1. July 11, 2013 Solutions

Lab 2: Static Response, Cantilevered Beam

Calculus I Homework: The Derivatives of Polynomials and Exponential Functions Page 1

Symbolic Solution of higher order equations

OR MSc Maths Revision Course

Chapter 12: Iterative Methods

USE OF MATLAB TO UNDERSTAND BASIC MATHEMATICS

FF505 Computational Science. Matrix Calculus. Marco Chiarandini

Linear Algebra- Final Exam Review

MATLAB Project 2: MATH240, Spring 2013

Taylor and Maclaurin Series. Approximating functions using Polynomials.

Math 308 Week 8 Solutions

Math 315: Linear Algebra Solutions to Assignment 7

18.S34 linear algebra problems (2007)

L3: Review of linear algebra and MATLAB

MATH 3321 Sample Questions for Exam 3. 3y y, C = Perform the indicated operations, if possible: (a) AC (b) AB (c) B + AC (d) CBA

Project One: C Bump functions

Eigenvalues and Eigenvectors

Chapter 2: Numeric, Cell, and Structure Arrays

1. What is the determinant of the following matrix? a 1 a 2 4a 3 2a 2 b 1 b 2 4b 3 2b c 1. = 4, then det

Full-State Feedback Design for a Multi-Input System

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB

Dimension. Eigenvalue and eigenvector

Eigenvalues and Eigenvectors

Math 314H Solutions to Homework # 3

CSL361 Problem set 4: Basic linear algebra

Appendix A: Matrices

8.7 Taylor s Inequality Math 2300 Section 005 Calculus II. f(x) = ln(1 + x) f(0) = 0

Introduction to MATLAB

Math Assignment 3 - Linear Algebra

Math 307 Learning Goals

Reduction to the associated homogeneous system via a particular solution

= = 3( 13) + 4(10) = = = 5(4) + 1(22) =

3.1 SOLUTIONS. 2. Expanding along the first row: Expanding along the second column:

MATRICES. a m,1 a m,n A =

Polynomial Solutions of the Laguerre Equation and Other Differential Equations Near a Singular

1 Last time: least-squares problems

Chapter 5. Linear Algebra. A linear (algebraic) equation in. unknowns, x 1, x 2,..., x n, is. an equation of the form

JUST THE MATHS UNIT NUMBER DIFFERENTIATION APPLICATIONS 5 (Maclaurin s and Taylor s series) A.J.Hobson

ECE 102 Engineering Computation

Linear Algebra Practice Problems

MA 265 FINAL EXAM Fall 2012

a11 a A = : a 21 a 22

MA 262, Fall 2017, Final Version 01(Green)

235 Final exam review questions

Econ Slides from Lecture 7

Linear Algebra Review. Fei-Fei Li

Matlab Instruction Primer; Chem 691, Spring 2016

Transcription:

Experiment : Introduction to MATLAB II.Vector, Matrix and Array Commands Some of MATLAB functions operate essentially on a vector (row or column), and others on an m-by-n matrix (m >= ). Array find length linspace logspace max min prod reshape size sort sum Commands Finds indices of nonzero elements. Computers number of elements. Creates regularly spaced vector. Creates logarithmically spaced vector. Returns largest element. Returns smallest element. Product of each column. Change size Computes array size. Sorts each column. Sums each column. >> = [ 0 4-0 0 0 8 6]; indices = find() indices = 4 8 9 >> indices = find(>) indices = 8 9 >> length() 9 >> max() 8 >> min() - > sort() - 0 0 0 0 4 6 8 >> sum() 6

>> sum(,) 6 >> sum(,) 0 4-0 0 0 8 6 >> Create a vector of 4 linearly spaced numbers from to : >> A = linspace(,,4) A =.0000 4.6667 8..0000. Matrix Functions Much of MATLAB s power comes from its matrix functions. Some useful ones are: eig inv poly det size rank eigenvalues and eigenvectors inverse characteristic polynomial determinant size rank [V,D] = eig(a) produces matrices of eigenvalues (D) and eigenvectors (V) of matrix A M = magic(n) returns an n-by-n matrix constructed from the integers through n^ with equal row and column sums. The order n must be a scalar greater than or equal to. >> A=magic() A = 8 6 5 7 4 9 >> [c d]=eig(a) c = -0.5774-0.8-0.46-0.5774 0.474-0.474-0.5774 0.46 0.8 d = 5.0000 0 0 0 4.8990 0 0 0-4.8990

. Calculus The Symbolic Math Toolbox provides functions to do the basic operations ofcalculus; differentiation, limits, integration, summation, and Taylor seriesexpansion. The following sections outline these functions.. Differentiation diff(f) differentiates f with respect to its symbolic variable (in this case x) Let s create a symbolic expression. >>syms a x f = sin(a*x) diff(f) f = sin(a*x) a*cos(a*x) To differentiate with respect to the variable a, type diff(f,a) which returns df / da cos(a*x)*x To calculate the second derivatives with respect to x and a, respectively, type diff(f,) or diff(f,x,) which return -sin(a*x)*a^. Limits The fundamental idea in calculus is to make calculations on functions as a Variable getscloseto orapproachesacertainvalue. Recallthatthedefinition of the derivative is given by a limit provided this limit exists. The Symbolic Math Toolbox allows you to computethe limits of functions in a direct manner. And >>syms h n x limit( (cos(x+h) - cos(x))/h,h,0 ) -sin(x)

limit( ( + x/n)^n,n,inf ) exp(x) In the case of undefined limits, the Symbolic Math Toolbox returns NaN (not a number). The command limit(/x,x,0) or limit(/x) returns NaN Observe that the default case,limit(f) is the same as limit(f,x,0).explore the options for the limit command in this table. Here, we assume that f is a function of the symbolic object x. Mathmatical Operation lim f ( x) x 0 lim f ( x) xa lim f ( x) xa lim f ( x) xa MATLAB command Limit(f) Limit(f,x,a) Limit(f,x,a, left ) Limit(f, x,a, right ). Integration If f is a symbolic expression, then the integration of f int(f) We can do this in (at least) three different ways. The shortest is: >>int( xˆ ) /*xˆ Alternatively, we can define x symbolically first, and then leave off the single quotes in theint statement. >>syms x >>int(xˆ) /*xˆ 4

Mathematical Operation MATLAB Command int(x^n) or int(x^n,x) >>int(sin(*x),x,0,pi/) >> g = 'cos(a*t + b)' g = cos(a*t + b) >>int(g) sin(b + a*t)/a 4.Solving Equations Solving Algebraic Equations If S is a symbolic expression,solve(s)attempts to find values of the symbolic variable in S (as determined byfindsym) for which S is zero. For example, >>syms a b c x S = a*x^ + b*x + c; solve(s) -(b + (b^ - 4*a*c)^(/))/(*a) -(b - (b^ - 4*a*c)^(/))/(*a) This is a symbolic vector whose elements are the two solutions. Ifyouwanttosolveforaspecificvariable,youmustspecifythatvariableasanadditional argument. For example, if you want to solve S for b, use thecommand >> b = solve(s,b) b = -(a*x^ + c)/x Note that these examples assume equations of the form f(x) = 0. If you needto solve equations of the form f(x)=q(x) you must use quoted strings. Inparticular, the command s = solve('cos(*x)+sin(x)=') s = 0 pi/6 (5*pi)/6 5

4. Several Algebraic Equations Now let s look at systems of equations. Suppose we have the system and we want to solve for x and y. First create the necessary symbolic objects. There are several ways to address the output of solve. One is to use a two-output call >>syms x y alpha >> [x,y] = solve(x^*y^, x-y/-alpha) x = alpha 0 y = 0 (-)*alpha 5: Single Differential Equation The function dsolve computes symbolic solutions to ordinary differentialequations. The equations are specified by symbolic expressions containing theletter D to denote differentiation. The symbols D, D,... DN, correspond to thesecond, third,..., Nth derivative, respectively. Thus, Dy is the Symbolic Mathof The dependent variables are those preceded byd and the default independent variable is t. Note that names of symbolicvariablesshouldnotcontaind.theindependentvariablecanbechangedfromt to some other symbolic variable by including that variable as the last inputargument. Initial conditions can be specified by additional equations. If initial conditions are not specified, the solutions contain constants of integration, C, C, etc. The output from dsolve parallels the output from solve. That is, you can call D solve with the number of out put variables equal to the number of dependent variables or place the output in a structure whose fields contain the solutions of the differential equations. Example The following call to dsolve dsolve('dy=+y^') uses y as the dependent variable and t as the default independent variable. The output of this command is >>dsolve('dy=+y^') i -i tan(c4 + t) 6

7 To specify an initial condition, use y = dsolve('dy=+y^','y(0)=') y = tan(t+/4*pi) Notice that y is in the MATLAB workspace, but the independent variable t is not. Thus, the command diff(y,t) returns an error. To place t in the workspace, type syms t. 6.Linear algebra in MATLAB Solving Equation One of the most important problems in technical computing is the solution of simultaneous linear equations. In matrix notation, this problem can be stated as follows. we may need to find x, x, and x so that 4 6 The problem can be rewritten in matrix-vector notation. We introduce a matrix A and a vector b by ; 4 6 b A Now we want to find the solution vector so that b A A = [ -; - -6 4 ; - - ] b = [ ; -; ] = A\b Matlab should give the solution

7. Polynomial Roots and Characteristic Polynomial If p is a row vector containing the coefficients of a polynomial, roots(p) returns a column vector whose elements are the roots of the polynomial. If r is a column vector containing the roots of a polynomial, poly(r) returns a row vector whose elements are the coefficients of the polynomial. To find the roots of following polynomial S 6 9S 5.5S 4 6.5S 67.75S 4.75S 5 The polynomial coefficients are entered in a row vector in descending powers. The roots are found using roots. p = [ 9.5 6.5 67.75 4.75 5 ] r = roots(p) The polynomial roots are obtained in column vector r = -4.0000 -.0000 -.0000 +.0000i -.0000 -.0000i 0.0000 + 0.5000i 0.0000-0.5000i If we want to find the coefficient of polynomial that has the roots-, -, - j4. We write this r = [- - -+4i --4i ] p = poly(r) The coefficients of the polynomial equation are obtained in a row vector. p = 9 45 87 50 Therefore, the polynomial equation is S 4 9S 45S 87S 50 0 8

Polynomial Evaluation If c is a vector whose elements are the coefficients of a polynomial in descending powers, the polyval(c, x) is the value of the polynomial evaluated at x. For example, to evaluate the above polynomial at points 0,,,, and 4, use the commands >> c = [ ]; x = 0::4; y = polyval(c, x) y = 7 55 09 You may use the following functions; try to find out its function Polyval,polyvalm 8. Laplace Transformation The laplace Transformation in MATLAB is very easy way. MATLAB has a function called (laplace) which transfer a function from time-domain to S- Domain.Befor you use this function you must declare the variable by symsfunction,see the below examble >>syms t >>laplace(t^5) 0/s^6 To get the laplaceinverse it is very easy also, only use ilaplace after decler the variable >>syms s ilaplace(/(s-)) exp(t) Or by using Partial-Faction Expansion with MatLab as below example 9

Consider the following transfer function: S 5S S 6 S 6S S 6 we write num=[ 5 6] den=[ 6 6] [r,p,k]=residue(num,den) r p k -6-4 - - - Which mean 6 S 4 S S 0

Exercise. Write an M-file to code the function g( x) ( x )exp( x (a.) Test your function by evaluating it at x and x. (b.) Test that your function works correctly when x is a vector by evaluating =[ 4 5 0 ] (c.) Plot your function for x using both fplot and the plot command (learn more about fplot).. Find the inverse laplace transforms and the partial fraction of ) a. b. S ( S 9) (S 4S 08) S( S 6) - Use symbolic integration to fined 4- solve 5- find the second derivative of f(x)=sin(e x ). 6- find the derivative of f(x,y)=x y 4 +ysinx. ( ) 7- solve 8-solve ( ) ( )