Presentation is loading. Please wait.

Presentation is loading. Please wait.

MATLAB Basics. The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt.

Similar presentations


Presentation on theme: "MATLAB Basics. The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt."— Presentation transcript:

1 MATLAB Basics

2 The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt.

3 Simple computations are very easy. Just type in exactly what you want computed and press enter. If no variables are used, the answer will automatically be assigned to the variable ans.

4 This variable can be used later, but don't forget that it will automatically be overwritten when a new computation is done.

5 Variables are also easy to use. Simply type a variable name, the equal sign, and then some value to be assigned.

6 At any time, you can type "whos" at the command line to see what variables have been assigned.

7 Other common mathematical functions are available such as square root, trigonometric functions, exponential functions, etc. Refer to the help window under the help menu for the syntax of these functions. Most of the common mathematical functions are listed in the file matlab/elfun.

8 Calculus

9 To perform symbolic differentiation or integration, you must first declare a symbolic variable. This is done by typing "syms x" where x is the variable name. In the following example, x is declared as symbolic and then used to find the indefinite integral and derivative of a function.

10 The definite integral can also be computed by adding the lower and upper bounds, separated by commas, after the function to integrate. (Note that a function of a valid symbol is still required)

11 MATLAB Complex Numbers

12 The variable i is already defined as the square root of -1. We can verify this by calculating i * i.

13 Arithmetic with imaginary numbers is very straightforward.

14

15 The functions abs and angle allow us to convert the complex number from rectangular to polar form.

16 Angle returns the phase angle in radians, but converting to degrees we see that the answer is what we expected.

17 MATRICES

18 Matrices are the basis of Matlab, so manipulating them is very simple. First, you input matrices by placing the values in brackets, with semicolons separating the rows.

19 Matrices of the same dimensions can be added and subtracted, and conformable matrices can be multiplied.

20

21 Finding the determinant or the inverse of a matrix is also simple.

22 These functions are particularly useful in circuit analysis, where it is necessary to solve several simultaneous equations. For example, if analysis yielded the equations: 7v1 - 4v2 - 2v3 = 3 -4v1 + 9v2 - 2v3 = 0 -2v1 - 2v2 + 5v3 = -12

23 It would be very easy to solve for the unknowns. First, create a 3x3 matrix with the coefficients of v1, v2, and v3, then create a 1x3 matrix with the right hand side of the equations. Finally, multiply the inverse of the first matrix with the second matrix, and the resulting matrix contains the answers.

24 This method also will work with symbolic variables. For example, you can solve for equations when using a Laplace transform by declaring s as a symbol ("syms s") and then entering the values into the matrix.

25 Sometimes the way the answers are given is somewhat confusing. The answers to the last example are: i1 = (s² + 3s + 4) / [(s+3)(s3 + 8s² + 11s + 20)] i2 = 2s / [(s+3)(s3 + 8s² + 11s + 20)]

26 MATLAB POLYNOMIALS & RATIONAL FUNCTIONS

27 Matlab also provides tools for manipulating polynomials and rational functions. To use these tools, the polynomial should be represented as a vector with the leftmost number being the highest power and the rightmost number being the constant. For example, x² + 2x + 1 would be represented as [1 2 1]. The roots function gives the roots of the polynomial and polyval evaluates the polynomial at the given value. Multiplying and dividing polynomials can be done with conv and deconv

28 To multiply x² + 2x + 1 and x + 1, we use

29 Note that deconv will return two vectors, the first contains the coefficients for the quotient polynomial, and the second contains the coefficients for the remainder polynomial. The following example divides x3 + 3x² + 3x + 2 by x + 1 If the left hand side of the equation didn't contain two variables, the answer would only have the quotient and the remainder would be discarded.

30 Matlab also has a function that will give the partial fraction decomposition of a rational function. This is very useful when working with Laplace transforms. The function residue takes two polynomials and returns the residues, the poles, and the direct term (quotient).

31 The partial fraction expansion of (2s + 5) / (s3 + 5s² + 8s + 4) is found by

32 There is a pole at –1 and a repeated pole at –2. There is no direct term since the order of the numerator was less than the order of the denominator. (2s + 5) / (s3 + 5s² + 8s + 4) = -3 / (s + 2) -1 / (s + 2)² + 3 / (s + 1)


Download ppt "MATLAB Basics. The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt."

Similar presentations


Ads by Google