1. Trang chủ
  2. » Công Nghệ Thông Tin

introduction to matlab tut

28 190 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 28
Dung lượng 661 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Display Windows con’t…• Graphic Figure Window – Displays plots and graphs • E.g: surfmagic30 – Created in response to graphics commands.. • M-file editor/debugger window – Create and edi

Trang 1

Introduction to MATLAB

January 18, 2008

Steve Gu

Trang 2

Part I: Basics

• MATLAB Environment

• Getting Help

• Variables

• Vectors, Matrices, and Linear Algebra

• Flow Control / Loops

Trang 3

Display Windows

Trang 4

Display Windows (con’t…)

• Graphic (Figure) Window

– Displays plots and graphs

• E.g: surf(magic(30)) – Created in response to graphics commands.

• M-file editor/debugger window

– Create and edit scripts of commands called M-files.

Trang 5

Getting Help

• type one of following commands in the command window:

– help – lists all the help topic

– help command – provides help for the

specified command

• help help – provides information on use of the

help command

– Google… of course

Trang 6

• Variable names:

– Must start with a letter

– May contain only letters, digits, and the underscore “_”

– Matlab is case sensitive, i.e one & OnE are different variables.

1234

NOTE: when a semi-colon

”;” is placed at the end of each command, the result

is not displayed.

Trang 7

– Inf or inf : ∞ , infinity – NaN or nan: not-a-number

Trang 8

Vectors, Matrices and Linear Algebra

• Vectors

• Matrices

• Solutions to Systems of Linear Equations.

Trang 10

• The colon notation may be used to address a block of elements.

(start : increment : end)

start is the starting index, increment is the amount to add to each successive index, and end is the ending index A shortened format (start : end) may be used if increment is 1.

• Example:

>> x(1:3) ans =

0 0.7854 1.5708

NOTE: MATLAB index starts at 1.

 3rd element of vector x

Trang 11

Vectors (con’t…)

Some useful commands:

x = start:end create row vector x starting with start, counting by

one, ending at end

increment, ending at or before end

linspace(start,end,number) create row vector x starting with start, ending at

end, having number elements

y = x’ transpose of vector x

dot (x, y) returns the scalar dot product of the vector x and y.

Trang 12

A is an m x n matrix.

 A Matrix array is two-dimensional, having both multiple rows and multiple columns, similar to vector arrays:

 it begins with [, and end with ]

 spaces or commas are used to separate elements in a row

 semicolon or enter is used to separate rows

Trang 13

Matrices (con’t…)

• Matrix Addressing:

matrixname(row, column)

colon may be used in place of a row or column reference to

select the entire row or column.

Trang 14

Matrices (con’t…)

Transpose B = A’

Identity Matrix eye(n)  returns an n x n identity matrix

eye(m,n)  returns an m x n matrix with ones on the main diagonal and zeros elsewhere

Addition and subtraction C = A + B

C = A – BScalar Multiplication B = αA, where α is a scalar

Matrix Multiplication C = A*B

Matrix Inverse B = inv(A), A must be a square matrix in this case

rank (A)  returns the rank of the matrix A

Matrix Powers B = A.^2  squares each element in the matrix

C = A * A  computes A*A, and A must be a square matrix.Determinant det (A), and A must be a square matrix

more commands

A, B, C are matrices, and m, n, α are scalars

Trang 15

Solutions to Systems of Linear Equations

• Example: a system of 3 linear equations with 3 unknowns (x1, x2, x3):

3x1 + 2x2 – x3 = 10 -x1 + 3x2 + 2x3 = 5

231

123

x x

x x

10

b

Let :

Trang 16

Solutions to Systems of Linear Equations

• Solution by Matrix Division:

The solution to the equation

Trang 17

Flow Control: If…Else

Example: (if…else and elseif clauses)

Trang 18

Flow Control: Loops

the break statement

break – is used to terminate the execution of the loop.

Trang 19

Part II: Visualization

Trang 21

box on;

Trang 22

Advanced Visualization

Trang 23

Part III: Modelling Vibrations

Second Order Difference Equations

Trang 24

Modelling Vibrations

The equation for the motion:

Remark: Second Order Difference Equation

Trang 25

Modelling Vibrations

• How to use MATLAB to compute y?

• Let’s Do It !

Trang 26

Modelling Vibrations

Trang 28

Results

Ngày đăng: 24/10/2014, 23:41

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN