Getting started with Matlab Numerical Methods Appendix B help/techdoc/learn_matlab/learn_matlab.html.

Slides:



Advertisements
Similar presentations
3D Geometry for Computer Graphics
Advertisements

1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Least Squares example There are 3 mountains u,y,z that from one site have been measured as 2474 ft., 3882 ft., and 4834 ft.. But from u, y looks 1422 ft.
Solving Linear Systems (Numerical Recipes, Chap 2)
3_3 An Useful Overview of Matrix Algebra
Dan Witzner Hansen  Groups?  Improvements – what is missing?
Computer Graphics Recitation 5.
Some useful linear algebra. Linearly independent vectors span(V): span of vector space V is all linear combinations of vectors v i, i.e.
Solution of Simultaneous Linear Algebraic Equations: Lecture (I)
Lecture tjwc - 17-Jun-15ISE1/EE2 Computing - Matlab Matlab Lecture 2: More MATLAB Programming u MATLAB has five flow control constructs:  if statements.
Linear Systems What is the Matrix?. Outline Announcements: –Homework III: due Wed. by 5, by Office Hours: Today & tomorrow, 11-1 –Ideas for Friday?
Ch 7.3: Systems of Linear Equations, Linear Independence, Eigenvalues
Ordinary least squares regression (OLS)
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.
Al-Amer An Introduction to MATLAB Dr. Samir Al-Amer Term 062.
Matrix Mathematics in MATLAB and Excel
INDR 262 INTRODUCTION TO OPTIMIZATION METHODS LINEAR ALGEBRA INDR 262 Metin Türkay 1.
Matrices CS485/685 Computer Vision Dr. George Bebis.
Linear Algebra & Matrices MfD 2004 María Asunción Fernández Seara January 21 st, 2004 “The beginnings of matrices and determinants.
Introduction The central problems of Linear Algebra are to study the properties of matrices and to investigate the solutions of systems of linear equations.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Scientific Computing Algorithm Convergence and Root Finding Methods.
3-Introduction to MATLAB Dr. Ahmet Zafer Şenalp Mechanical Engineering Department Gebze Technical.
Chapter 10 Review: Matrix Algebra
Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 8 Linear Algebraic Equations PowerPoint to accompany Copyright © 2010.
Engineering Analysis ENG 3420 Fall 2009
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
MATLAB Programming I Joy. Outline Examples What is Matlab? History Characteristics Organization of Matlab – Toolboxes Basic Applications Programming.
1 Statistical Computing in MATLAB AMS 597 Ling Leng.
SUNY-New Paltz Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz “Lecture 4”
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Review of Matrices Or A Fast Introduction.
Selection Programming EE 100. Outline introduction Relational and Logical Operators Flow Control Loops Update Processes.
Matlab Programming, part 1 M-files It is generally more convenient to program in Matlab using m-files, ascii text files containing a set of Matlab commands.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
CMPS 1371 Introduction to Computing for Engineers MATRICES.
8.1 Matrices & Systems of Equations
Lecture 28: Mathematical Insight and Engineering.
Chapter 3 Solution of Algebraic Equations 1 ChE 401: Computational Techniques for Chemical Engineers Fall 2009/2010 DRAFT SLIDES.
Intro to Matlab 1.Using scalar variables 2.Vectors, matrices, and arithmetic 3.Plotting 4.Solving Systems of Equations Can be found at:
Introduction to MATLAB
Part 3 Chapter 11 Matrix Inverse and Condition Part A All images copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Solving Linear Systems of Equations
Linear algebra: matrix Eigen-value Problems Eng. Hassan S. Migdadi Part 1.
Scientific Computing General Least Squares. Polynomial Least Squares Polynomial Least Squares: We assume that the class of functions is the class of all.
OUTLINE Overview Numbers, variables and similar in Matlab
Lesson 3 CSPP58001.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Introduction to Matlab Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Intermediate Value Theorem Vince Varju. Definition The Intermediate Value Theorem states that if a function f is a continuous function on [a,b] then there.
Introduction to MATLAB 7
Matlab Tutorial 1 David Goldstein University of Colorado Dept of Aerospace Engineering Sciences.
Instructor: Mircea Nicolescu Lecture 8 CS 485 / 685 Computer Vision.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Introduction to MATLAB Farida Mosally Mathematics Department King Abdulaziz University 2013.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 8 Linear Algebraic Equations and Matrices.
MATLAB ……………….matrix laboratory. Bhushan D Patil PhD Research Scholar Department of Electrical Engineering Indian Institute of Technology, Bombay Powai,
Tutorial on Matlab Basics
Introduction to MATLAB
Introduction The central problems of Linear Algebra are to study the properties of matrices and to investigate the solutions of systems of linear equations.
Introduction The central problems of Linear Algebra are to study the properties of matrices and to investigate the solutions of systems of linear equations.
Linear Algebra Lecture 2.
Elementary Linear Algebra Anton & Rorres, 9th Edition
Statistical Computing in MATLAB
Euclidean Inner Product on Rn
MATLAB EXAMPLES Matrix Solution Methods
CS485/685 Computer Vision Dr. George Bebis
Elementary Linear Algebra Anton & Rorres, 9th Edition
Subject :- Applied Mathematics
Presentation transcript:

Getting started with Matlab Numerical Methods Appendix B help/techdoc/learn_matlab/learn_matlab.html

Linear Algebra with Matlab Introduction of Basic Matlab functions

Solve Solve Ax=b Ax=b Matlab Matlab x= A\b

trace(A) >> A=[1 3 6;2 1 9; 3 6 1] >> A=[1 3 6;2 1 9; 3 6 1] A = A = >> trace(A) >> trace(A) ans = ans = 3 3

rank() >> B=[1 2 3; 3 4 7; ;-2 5 3; ] >> B=[1 2 3; 3 4 7; ;-2 5 3; ] B = B = >> rank (B) >> rank (B) ans = ans = 3 3 Number of independent rows

Reduced row echelon form;rref(B) >> B=[1 2 3; 3 4 7; ;-2 5 3; ]; >> B=[1 2 3; 3 4 7; ;-2 5 3; ]; >> rref(B) >> rref(B) ans = ans =

inv(A) >> A=rand(3,3) >> A=rand(3,3) A = A = >> inv(A) >> inv(A) ans = ans = >> A*inv(A) >> A*inv(A) ans = ??? ans = ???

det(A) >> A=rand(3,3) >> A=rand(3,3) A = A = >> det(A) >> det(A) ans = ans =

Ax=b; x=A\b >> A=rand(3,3) >> A=rand(3,3) A = A = >> b=rand(3,1) >> b=rand(3,1) b = b = >> x = A\b >> x = A\b x = x = >> A*x >> A*x ans = ans =

tic, toc, elapsed_time >> tic >> tic >> toc >> toc elapsed_time = elapsed_time = >> tic >> tic >> x=toc >> x=toc x = x =

time.m A=rand(1000,1000); A=rand(1000,1000); tic tic inv(A); inv(A); time_to_inverse_A=toc time_to_inverse_A=toc

output functions disp( ‘ strings to be shown on screen ’ ); disp( ‘ strings to be shown on screen ’ ); fprintf( ‘ As C language %8.2f\n ’, ver1); fprintf( ‘ As C language %8.2f\n ’, ver1); >> ver1= >> ver1= >> fprintf('As C language %8.2f\n', ver1); >> fprintf('As C language %8.2f\n', ver1); As C language 1.33 As C language 1.33

norm(V,n) v=[3, 4] v=[3, 4] norm(v,1) norm(v,1) ans = ans = 7 7 norm(v) norm(v) ans = ans = 5 5 norm(v,3) norm(v,3) ans = ans = norm(v,inf) norm(v,inf) ans = ans = 4 4 ||V|| 1 =(|v1|+|V2|+…|Vn | ) ||V|| 1 =(|v1|+|V2|+…|Vn | ) ||V|| 2 =(|v1| 2 +|V2| 2 +…|V n| 2 ) -2 ||V|| 2 =(|v1| 2 +|V2| 2 +…|V n| 2 ) -2 ||V|| 3 =(|v1| 3 +|V2| 3 +…|V n| 3 ) -3 ||V|| 3 =(|v1| 3 +|V2| 3 +…|V n| 3 ) -3 ||V|| inf =(|v1| ∞ +|V2| ∞ +…|Vn| ∞ ) - ∞ ||V|| inf =(|v1| ∞ +|V2| ∞ +…|Vn| ∞ ) - ∞

If Ax=b has solution Then Then Ax =0 only when x=0 Ax =0 only when x=0 det(A) ≠0 det(A) ≠0 reff(A) = I reff(A) = I rank(A)=n rank(A)=n

LU decomposition >> A=rand(3) >> A=rand(3) A = A = >> [L1,U]=lu(A) >> [L1,U]=lu(A) L1 = L1 = U = U = >> [L,U,P]=lu(A) >> [L,U,P]=lu(A) L = L = U = U = P = P =

Cholesky decomposition >> A=[2 3 4; 3 6 7; ]; >> A=[2 3 4; 3 6 7; ]; >> P=chol(A) >> P=chol(A) P = P = >> P'*P-A >> P'*P-A ans = ans = 1.0e-015 * 1.0e-015 * A is positive definite symmetric A is positive definite symmetric A=P T P A=P T P

QR decomposition A = A = >> [Q,R]=qr(A) >> [Q,R]=qr(A) Q = Q = R = R = Q Orthogonal matrix R Upper triangle matrix

Singular Value Decomposition >> A = [ ; ; ] >> A = [ ; ; ] >> [U,S,V]=svd(A) >> [U,S,V]=svd(A) U = U = S = S = V = V = >> U*S*V' >> U*S*V' ans = ans = A=USV T A=USV T A.. m x n U.. m x m S.. m x n (singular value) V.. n x n

Reduce 3 columns V = V = >> U*S*V' >> U*S*V' ans = ans =

Pseudo-inverse A = A = >> Aplus=pinv(A) >> Aplus=pinv(A) Aplus = Aplus = >> Aplus*A >> Aplus*A ans = ans = >> A*Aplus >> A*Aplus ans = ans = Since A is not n by n, there is no inverse A -1. Since A is not n by n, there is no inverse A -1. Ax=b can be solved by pseudo-inverse A +. Ax=b can be solved by pseudo-inverse A +. x = A + * b x = A + * b

cond(A), rcond(A) >> A=eye(3).*20 >> A=eye(3).*20 A = A = >> [cond(A) rcond(A)] >> [cond(A) rcond(A)] ans = ans = cond(A) =1 cond(A) =1 A is perfectly conditioned stable cond(A) > large number cond(A) > large number A is ill-conditioned too sensitive rcond is a rapid version of cond rcond is a rapid version of cond rcond~1/cond

Condition of a Hilbert matrix >> hilb(4) >> hilb(4) ans = ans = >> cond(hilb(4)) >> cond(hilb(4)) ans = ans = e e+004

Matlab Programming

if, else, and elseif if A > B 'greater' 'greater' elseif A < B 'less' elseif A == B 'equal'else error('Unexpected situation') end

switch and case switch (rem(n,4)==0) + (rem(n,2)==0) case 0 M = odd_magic(n) case 1 M = single_even_magic(n) case 2 M = double_even_magic(n) otherwise error('This is impossible') end

for for n = 3:32 r(n) = rank(magic(n)); end r Display the result

While a = 0; fa = -Inf; b = 3; fb = Inf; while b-a > eps*b x = (a+b)/2; fx = x^3-2*x-5; if sign(fx) == sign(fa) a = x; fa = fx; else b = x; fb = fx; end x The result is a root of the polynomial x^3 - 2x - 5 x = (bisection method)

continue fid = fopen('magic.m','r'); count = 0; while ~feof(fid) line = fgetl(fid); if isempty(line) | strncmp(line,'%',1) continue end count = count + 1; end disp(sprintf('%d lines',count));

break a = 0; fa = -Inf; b = 3; fb = Inf; while b-a > eps*b x = (a+b)/2; fx = x^3-2*x-5; if fx == 0 break elseif sign(fx) == sign(fa) a = x; fa = fx; else b = x; fb = fx; end end x

try - catch try statement... statement catch statement... statement end

return function d = det(A) %DET det(A) is the determinant of A. if isempty(A) d = 1; return else... end return terminates the current sequence of commands and returns control to the invoking function

GUIDE

GUIDE

Blank GUI

M-file editor

Tools ->Run

GUI with Axes and Menu

Run

M-file editor

Try it yourself, and think about how to use it.