응용 전산 및 실습 MATLAB – Chapter 3 행렬연산

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
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.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
CIS 101: Computer Programming and Problem Solving Lecture 2 Usman Roshan Department of Computer Science NJIT.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Introduction to MATLAB ES 156 Signals and Systems 2008 Harvard SEAS.
MATLAB TUTORIAL Dmitry Drutskoy Some material borrowed from the departmental MATLAB info session by Philippe Rigollet Kevin Wayne.
Introduction to MATLAB ES 156 Signals and Systems 2007 Harvard SEAS Prepared by Jiajun Gu.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Chapter 10 Review: Matrix Algebra
Scientific Computing Linear Systems – LU Factorization.
Matlab tutorial course Lesson 2: Arrays and data types
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
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,
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
CMPS 1371 Introduction to Computing for Engineers MATRICES.
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
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.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
Numerical Computation Lecture 6: Linear Systems – part II United International College.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
Tutorial on Matlab Basics
ECE 1304 Introduction to Electrical and Computer Engineering
Linear Algebraic Equations and Matrices
Manipulating MATLAB Matrices Chapter 4
Introduction to MATLAB
L – Modeling and Simulating Social Systems with MATLAB
Chapter 3 Arrays and Vectors
Math. 375, Fall Matrices and Vectors
Linear Algebraic Equations and Matrices
Introduction to Programming for Mechanical Engineers (ME 319)
Basic operations in Matlab
Seminar 1 for DCSP Using Matlab.
Matlab Workshop 9/22/2018.
EEE 244 Numerical Methods In Electrical Engineering
StatLab Matlab Workshop
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
Digital Image Processing using MATLAB
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Matlab tutorial course
Lecture 2 Introduction to MATLAB
Introduction to MATLAB [Vectors and Matrices] Lab 2
Vectors and Matrices Chapter 2 Attaway MATLAB 4E.
How to Use MATLAB A Brief Introduction.
CS 111 Introduction to Computing in Engineering and Science
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
Presentation transcript:

응용 전산 및 실습 MATLAB – Chapter 3 행렬연산 위덕대학교 에너지전기공학부 이 성 환 Chapter 3 Uiduk University

MATLAB – Scripting M-File REVIEW MATLAB 메뉴의 File  New  M-File 선택 M-File Editor 가 실행되며 다음과 같이 화면에 나타남 원하는 MATLAB 명령어 입력 (명령어 입력 시 절대 한글을 사용하지 말 것!) File  Save 를 선택하고 원하는 경로에 원하는 파일 이름으로 저장 (파일 이름에 절대 한글을 쓰지 말 것!) Debug  Run 을 선택하여 생성한 M-File을 실행하면 MATLAB Command Window에 결과가 나타남 Chapter 3 Uiduk University

MATLAB – Enhancing M-File REVIEW Keyword / Function Meaning Example ; Suppress output radius = 5; % Comment radius = 5; % 반지름 값 disp(variable) Display results without identifying variable names disp(radius) echo Control the ‘Command Window’ echoing of script file commands input Prompt user for input radius = input(‘반지름을 입력하세요> ‘); pause Pause until user presses any key pause(n) Pause for n seconds, then continue pause(3) fprintf(format, var1, var2,,,) Print msg fprintf(‘계산이 완료되었습니다.’); fprintf(‘반지름은 %f 입니다.\n’, radius); waitforbuttonpress Pause until user presses mouse button or keyboard key Chapter 3 Uiduk University

MATLAB – Array Definition MATLAB – Array Calculation REVIEW Keyword Meaning [ ] 배열의 시작과 끝 ; 행 구분 , 열 구분 MATLAB – Array Calculation Operation Symbol Example Addition, a + b + A + B Subtraction, a – b - A – B Multiplication, a • b * A * B Division, a  b / or inv() A / B = A * inv(B) Exponentiation, ab ^ A ^ 2 Transposition, aT ‘ A’ Chapter 3 Uiduk University

MATLAB – Solving Linear Equations REVIEW EX6) Solving the following linear equations >> A = [1, -1, 2; 3, 2, 9; 0, 1, -4] A = 1 -1 2 3 2 9 0 1 -4 >> B = [10; 9; 3] B = 10 9 3 >> x = inv(A) * B x = 6.4783 -4.0435 -0.2609 Chapter 3 Uiduk University

MATLAB – Scalar and Array Operation REVIEW Element-By-Element Operation Representative Data Scalar Addition Scalar Multiplication Array Addition Array Multiplication Array Division Array Exponentiation Chapter 3 Uiduk University

MATLAB – Standard Arrays REVIEW Keyword Description ones(n) ones(m, n) Create n x n arrays containing all ones Create m x n arrays containing all ones zeros(n) zeros(m, n) Create n x n arrays containing all zeros Create m x n arrays containing all zeros eye(n, n) eye(m, n) Produce n x n identity matrices Produce m x n identity matrices rand(n) rand(m, n) Uniformly distributed n x n random arrays Uniformly distributed m x n random arrays randn(n) randn(m, n) Zero-mean, unit-variance normal distribution n x n, m x n random arrays size(A) Return row & column size Chapter 3 Uiduk University

MATLAB – Easy Array Construction Array Construction Technique Description x = [ 2, 2*pi, sqrt(5), 2-3j ] Create row vector x containing element specified x = first : last Create row vector x starting with first, counting by one, ending at or before last x = first : increment : last Create row vector x starting with first, counting by increment, ending at or before last x = linspace(first, last, n) Create row vector x starting with first, ending at last, having n elements x = logspace(first, last, n) Create logarithmically-spaced row vector x starting with 10first, ending at 10last, having n elements Chapter 3 Uiduk University

MATLAB – Easy Array Construction EX1) >> c = [1, 6, 9, 7] c = 1 6 9 7 >> a = 1 : 5 a = 1 2 3 4 5 >> b = 1 : 2 : 7 b = 1 3 5 7 >> x = (0 : 0.1 : 0.3) * pi x = 0 0.3142 0.6238 0.9425 EX2) >> d = [ 1:2:5, 1, 0, 1 ] d = 1 3 5 1 0 1 >> a = 1 : 3, b = 1 : 2 : 7 a = 1 2 3 b = 1 3 5 7 >> c = [ b, a ] c = 1 3 5 7 1 2 3 EX3) >> x = linspace(2, 6, 3) x = 2 4 6 >> x = logspace(0, 2, 11) 1.0000 1.5849 2.5119 3.9811 6.3096 10.0000 15.8489 25.1189 39.8107 63.0957 100.0000 Chapter 3 Uiduk University

MATLAB – Complex Array’s Transpose Pitfall 1 2 3 >> d = a + i * a d = 1.0000 + 1.0000i 2.0000 + 2.0000i 3.0000 + 3.0000i >> e = d’ % Complex conjugate transpose of d e = 1.0000 - 1.0000i 2.0000 - 2.0000i 3.0000 - 3.0000i >> f = d.’ % Dot transpose = Transpose of d 1.0000 + 1.0000i 2.0000 + 2.0000i 3.0000 + 3.0000i Chapter 3 Uiduk University

MATLAB – Array Addressing Description A(r, c) Indicates the elements by the r’th row and the c’th column A(r, : ) Addresses a subarray within A defined by the index vector of desired rows in r and all columns A( : , c) Addresses a subarray within A defined by all rows and the index vector of desired columns in c A( a : b , c : d) Addresses a subarray within A intersected by the rows from a to b and the columns from c to d Chapter 2 Uiduk University

MATLAB – Array Addressing EX5) >> A = [1, 2, 3; 4, 5, 6; 7, 8, 9] A = 1 2 3 4 5 6 7 8 9 >> A(3, 3) = 0 7 8 0 >> A(2, 6) = 1 % extends array A 1 2 3 0 0 0 4 5 6 0 0 1 7 8 0 0 0 0 EX6) >> A( : , 4) = 4 A = 1 2 3 4 0 0 4 5 6 4 0 1 7 8 0 4 0 0 >> B = A(1 : 2, 2 : 3) B = 2 3 5 6 >> A( :, 2) = [ ] % removes 2nd column 1 3 4 0 0 4 6 4 0 1 7 0 4 0 0 Chapter 3 Uiduk University

MATLAB – Array Addressing EX7) >> A = [1, 2, 3; 4, 5, 6; 7, 8, 9] A = 1 2 3 4 5 6 7 8 9 >> B = [1, 4, 7] B = 1 4 7 >> A(2, : ) = B % substitutes 2nd row Chapter 3 Uiduk University

MATLAB – Array Manipulation Function Description rot90(A) rot90(A, k) Rotates vector A by 90 degrees Rotates vector A by 90 degrees * k (k > 0 = ccw, k < 0 = cw) flipud(A) Flips array in up-down direction fliplr(A) Flips array in the left-right direction triu(A) Extracts upper triangular part tril(A) Extracts lower triangular part diag(A) Extracts diagonal elements cross(A, B) Outer product of A and B : dot(A, B) = sum(A.*B) Inner product of A and B : Chapter 3 Uiduk University

MATLAB – Array Manipulation EX8) >> A = [1, 2, 3; 4, 5, 6; 7, 8, 9] A = 1 2 3 4 5 6 7 8 9 >> flipud(A) ans = >> fliplr(A) 3 2 1 6 5 4 9 8 7 EX9) >> rot90(A) ans = 3 6 9 2 5 8 1 4 7 >> diag(A) 1 5 9 >> diag(ans) 1 0 0 0 5 0 0 0 9 EX10) >> triu(A) ans = 1 2 3 0 5 6 0 0 9 >> A = [1, 2, 3]; >> B = [4, 5, 6]; >> dot(A, B) 32 >> cross(A, B) -3 6 -3 Chapter 3 Uiduk University

MATLAB – Reading From Data File << mat.txt>> 파일의 내용 0.7918 1.2590 -0.2172 -0.9242 2.6448 0.1716 -0.5228 0.3639 4.5700 -0.1982 0.0586 0.1214 6.4240 -0.0158 0.0763 -0.0615 8.3750 0.0303 -0.0131 -0.0144 10.2545 0.0003 -0.0104 0.0101 12.2296 -0.0044 0.0026 0.0014 14.1076 0.0003 0.0013 -0.0016 16.0704 0.0006 -0.0005 -0.0001 18.2613 -0.0001 -0.0001 0.0002 >> load mat.txt >> t = mat( : , 1); % 시간 벡터 >> x = mat( : , 2); % 변위 벡터 >> v = mat( : , 3); % 속도 벡터 >> a = mat( : , 4); % 가속도 벡터 Chapter 3 Uiduk University

MATLAB – Multidimensional Arrays >> A = zeros(2, 3) % start with a 2-D array A = 0 0 0 >> A( : , : , 2) = ones(2, 3) % add a second page to go 3-D ! A( : , : , 1) = A( : , : , 2) = 1 1 1 Chapter 3 Uiduk University