13
MATRIX ALGEBRA & MATLAB 1 MATRIX ALGEBRA & MATLAB 1 Lecture 2

lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

MATRIX ALGEBRA & MATLAB 1 MATRIX ALGEBRA & MATLAB 1

Lecture 2

Page 2: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

ContentsContents

1 B k d1. Background

2. Starting with MATLAB

3. Arrays

4 M th ti l ti ith4. Mathematical operations with arrays

5. Inverse of a matrix

6. Determinant of a matrix

7 Pl tti7. Plotting

8. M-file

9. Structures

Page 3: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

1. Background1. Background

MATLAB MAT i LAB tMATLAB = MATrix LABoratoryFields

mathematical computaionsmathematical computaionsmodeling and simulationsdata analysis and processingdata analysis and processingvisualization and graphicsalgorithm development

MATLAB is more easier than other programming languages( C C++ C# FORTRAN JAVA etc)languages( C, C++, C#, FORTRAN, JAVA… etc).Many applications : http://www.mathworks.com/

Matrix Analysis of Structures

Page 4: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

2.1 Organization2.1 Organization

C d Wi dCommand WindowMain window, enters variablse, runs programs.

Command WindowWorkspaceva ab se, u s p og a s.

WorkspaceProvides information Command History

about the variables that are used.

Command HistoryCommand HistoryLogs commands entered in the Command Window.

Edit Window

Edit WindowCreates and debugs script and function filesand function files.

Matrix Analysis of Structures

Page 5: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

2.2 Operations with scalars2.2 Operations with scalars

Operation Symbol Example

Addition + 5+3

Subtraction - 5-3

Multiplication * 5*3

Right division / 5/3Right division / 5/3

Left division \ 5\3=3/5

Exponentiation ^ 5^3(means 53)

Since a semicolon is typed at the end of the command,the value of B is not displayed.

Matrix Analysis of Structures

Page 6: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

2.3 Built-in math functions2.3 Built in math functions

Command Description Example ANS

sqrt (x) Square root. >>sqrt(81)

( ) E ti l ( ) (5)

xeexp (x) Exponential ( ). >>exp(5)

abs (x) Absolute value. >>abs(-24)

log (x) Natural logarithm. Base e logarithm (ln). >>log(1000)g ( ) g g ( )

log10 (x) Base 10 logarithm. >>log10(1000)

sin (x) Sine of angle x (x in radians). >>sin(pi/6)

sind (x) Sine of angle x (x in defrees). >>sind(30)

cf. The other trigonometric functions are written in the same way. The inverse trigonometric functions are written by adding the letter “a” in front, for example, asin(x)

d ( ) R d t th t i t d(17/5)round (x) Round to the nearest integer. >>round(17/5)

fix (x) Round toward zero. >>fix(13/5)

ceil (x) Round up toward infinity. >>ceil(11/5)

Matrix Analysis of Structures

( ) p y

floor (x) Round down toward minus infinity. >>floor(-9/4)

Page 7: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

2.4 Display format2.4 Display format

Command Description Example ANS

format shortFixed point with four decimal digits for:0.001 ≤ number ≤ 1000Otherwise display format short e

>> format short>>290/7

Otherwise display format short e.

format longFixed point with 14 decimal digits for:0.001 ≤ number ≤ 100Otherwise display format long e.

>>format long>>290/7

>>format short eformat short e Scientific notation with four decimal digits. >>format short e>>290/7

format long e Scientific notation with 15 decimal digits. >>format long e>>290/7

fo mat bank T o decimal digits >>format bankformat bank Two decimal digits. >>290/7

Matrix Analysis of Structures

Page 8: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

3.1 Creating a vector3.1 Creating a vector

variable name = [num num num]variable_name = [num num … num]generate (1×n) vector

variable name = m : q : na ab e_ a e qm : initial pointq : incrementn : end point

variable_name = linspace(xi, xf, n)

Matrix Analysis of Structures

Page 9: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

3.2 Creating a matrix3.2 Creating a matrix

variable name =[1st row elements; 2nd row elements; …; last row elements]

Array addressing : array_name(row, column)

variable_name [1st row elements; 2nd row elements; …; last row elements]

Matrix Analysis of Structures

Page 10: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

3.3 For Handling arrays3.3 For Handling arrays

Command Description Example ANS

length (A) Returns the number of elements in vector A >> A=[5 9 2 4];>>length(A)

Returns a row vector [m n] where m and

size (A)

Returns a row vector [m, n], where m and n are the size m× n of the array A.(m is number of rows. n is number of columns.)

>>A=[6 1 4 0 125 19 6 8 2];>>size(A)

Creates a matrix with m rows and nzeros (m, n)

Creates a matrix with m rows and ncolumns, in which all the elements are the number 0.

>>zr=zeros(3,4)

ones (m, n)Creates a matrix with m rows and ncolumns, in which all the elements are the >>ne=ones(4,3)( , ) ,number 1.

( , )

eye (n)Creates a square matrix with m rows and ncolumns in which the diagonal elements are equal to 1 (identity matrix)

>>idn=eye(5)

Matrix Analysis of Structures

Page 11: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

4.1 Addition and subtraction4.1 Addition and subtraction

⎥⎦

⎤⎢⎣

⎡=

232221

131211

AAAAAA

A ( 2 × 3 )

⎦⎣

⎥⎤

⎢⎡

= 131211 BBBB ( 2 × 3 )⎥

⎦⎢⎣

=232221 BBB

B ( 2 × 3 )

⎥⎤

⎢⎡ ±±±

=

±

131312121111 BABABABA

⎥⎦

⎢⎣ ±±±

=232322222121 BABABA

( 2 × 3 )

Matrix Analysis of Structures

Page 12: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

4.2 Multiplication & Division4.2 Multiplication & Division

Multiplication

⎥⎦

⎤⎢⎣

⎡=

232221

131211

AAAAAA

A ( 2 × 3 )

Multiplication

⎦⎣ 232221 AAA

⎥⎤

⎢⎡ 1211

BBBB

B⎥⎥⎥

⎦⎢⎢⎢

=

3231

2221

BBBBB ( 3 × 2 )

⎤⎡ CC⎥⎦

⎤⎢⎣

⎡=×=

2221

1211

CCCC

BAC ( 2 × 2 )

(?)AbxbAx =→=

Division

)(1 OKbAxbAx −=→=

Matrix Analysis of Structures

ADivision is not a defined operation in linear algebra.

Page 13: lec 2 [호환 모드]Microsoft PowerPoint - lec 2 [호환 모드] Author: Jeeho Lee Created Date: 12/20/2012 1:37:07 PM

4.3 Element-by-element operation4.3 Element by element operation

Symbol Description

.* Multiplication

^ Exponentiation. Exponentiation

./ Right division

.\ Left Division

Matrix Analysis of Structures