lec 01. introduction to matlab

Download Lec 01. Introduction to MATLAB

Post on 15-Jun-2015

2.272 views

Category:

Education

14 download

Embed Size (px)

TRANSCRIPT

  • 1. MATLAB ProgrammingMATLAB kmste2@kaist.ac.kr1

2. MATLAB Programming 1 20 ~ 1 29 (~) 14:00 ~ 18:00 ( 30) 50 , 10 MATLAB (2) MATLAB 7 ( kmste2@kaist.ac.kr ) ( ehgud5@kaist.ac.kr ) IT ( ita@kaist.ac.kr, 042-350-8941~3) 2 3. MATLAB ProgrammingMATLAB MATLAB GUI Interface , (, , ), , , , M- M- 2D, 3D ( , , 3 , ) , , , GUI Application 3 4. MATLAB Programming MATLAB MATLAB MATLAB / 4 5. MATLAB ProgrammingMATLAB? MATrix LABoratory total solution Script , Control System Toolbox Signal Processing Toolbox Image Processing Toolbox Wavelet Toolbox 5 6. MATLAB ProgrammingMATLAB? GUI InterfaceSimulink Model-based design tool device driver VxWare Embedded Solution MATLAB Code C, VHDL, 6 7. MATLAB ProgrammingMATLAB Early 1970s Linear algebra LINPACK , eigenvalue/eigenvector EISPACK Late 1970s Cleve Moler New Mexico LINPACK, EISPACK Fortran Cleve Moler1984 Cleve Moler Stanford . Jack Little . . MATLAB C . . Mathworks Jack Little 7 8. MATLAB ProgrammingMATLAB Cleve Moler http://www.mathworks.co.kr/company/aboutus/founders/clevemoler.html Jack Little http://www.mathworks.co.kr/company/aboutus/founders/jacklittle.html Origins of MATLAB http://www.mathworks.co.kr/videos/origins-of-matlab70332.html?type=shadow8 9. MATLAB Programming MATLAB , , curve fitting, , C++/Fortran , / , , , MATLAB C/C++ , HDL VHDL, Verilog , Cosimulation, , / 9 10. MATLAB Programming MATLAB FPGA , !! 10 11. MATLAB ProgrammingMATLAB !11 12. MATLAB ProgrammingMATLAB KAIST / MATLAB License (*@kaist.ac.kr) (*@*.kaist.ac.kr ) Mathworks http://circnts.kaist.ac.kr/ License (http://ajin.to) MATLAB MATLAB 12 13. MATLAB ProgrammingMATLAB circnts.kaist.ac.kr Etc Products MATLAB13 14. MATLAB ProgrammingMATLAB 14 15. MATLAB ProgrammingMATLAB KAIST I need to create an Account 15 16. MATLAB ProgrammingMATLAB Activation Key:16 17. MATLAB ProgrammingMATLAB (R2012b)17 18. MATLAB ProgrammingMATLAB Workspace EditorCurrent FolderCommand History Command Window18 19. MATLAB ProgrammingMATLAB Current Folder EditorCommand WindowWorkspaceWorkspace Editor Current FolderCommand History Command Window M- MATLAB MATLAB Excel spread sheet , Command History MATLAB 19 20. MATLAB ProgrammingMATLAB MATLAB Layout Default Editor 20 21. MATLAB ProgrammingCommand Window 21 22. MATLAB ProgrammingKeyboard Mapping 22 23. MATLAB ProgrammingMATLAB [] 2 x 3 , Workspace . 1. Command Window . >> A = [1 2 3; 4 5 6]2. Workspace A spread sheet .3. , X spread sheet . . >> A23 24. MATLAB ProgrammingMATLAB [] . 1. Command Window , (>>) .2. / . .3. Command History .24 25. MATLAB ProgrammingMATLAB MATLAB >> quitCommand Window >> clcMATLAB >> clear >> clear all, workspace delete , delete MATLAB >> help cos25 26. MATLAB Programming (C/JAVA ) = = , ! >> (variable) = (expression) >> A = 5 * 3 A= 15 >> a = A * 10 a= 150 ! . , , .MATLAB . a A .26 27. MATLAB Programming ? >> 5 * 3 + 6 MATLAB ans >> 5 * 3 + 6 ans = 26 ans >> ans * 3 ans = 6327 28. MATLAB Programming 6 1+ 5 8+ 2>> 8 + (6 * (1 + sqrt(5))) / 2>> exp(sqrt(3)) + pi * 10^3 MATLAB 4 103 3 3 + 103 1>> 4 / 3 * pi * 10^3>> exp(pi * sqrt(-1))or>> exp(pi * i) = 3.141592 pi e exp(1) . exp(x) i j (complex number) 28 29. MATLAB ProgrammingQuiz x = 5 , .3 sin 2 3 () 2 2 + 2 229 30. MATLAB ProgrammingQuiz Sol. x = 5 , .3 sin 2 3 () 2 2>> x = 5; >> - (3*sin(x)*cos(x)^2-sin(x)^3)/(x^2-2) ans = -0.0283 + 2 2>> x = 5; >> (exp(i*x)+exp(-i*x))/2 * (exp(i*x)-exp(-i*x))/(2*i) ans = -0.2720 30 31. MATLAB Programming (vector) ? : : MATLAB [ ] (space) (,) >> u = [-3 2 4 8 11] u= -3 2 4 8 11or>> u = [-3, 2, 4, 8, 11] u= -3 2 4 8 11(row) & (column) (;) >> u = [1; 2; 3] u= 1 2 3 31 32. MATLAB Programming (vector) () >> u = [-3 2 4] u= -3 2 4 >> u u= -3 2 4>> u = [-3; 2; 4] u= -3 2 4 >> u u= -3 2 4 >> u(1) ans = -3 >> u(2) ans = 2 >> u(3) ans = 4 1 >> u(4) Index exceeds matrix dimensions.32 33. MATLAB Programming [1, 2, 3, , 100] I: >> u = [1 2 3 4 5 100] .. .. ?? II: (colon operator) >> u = 1:100 !! III. linspace >> u = linspace(1,100,100)33 34. MATLAB Programming >> u = :/: : / / 1 1) -5 2 >> u = -5:2or>> u = -5:1:2 2) 2 -5 >> u = 2:-1:-5 3) 0 1 0.01 >> u = 0:0.01:134 35. MATLAB Programming linspace (linearly spaced vector) >> u = linspace(, , ) 100 1) -1 1 9 >> u = linspace(-1, 1, 9) ans = -1.0000 -0.7500 -0.5000 -0.250000.25000.50000.75001.0000 2) 1 -1 5 >> u = linspace(1, -1, 5) ans = 1.0000 0.50000 -0.5000 -1.000035 36. MATLAB Programming >> a = [1 2 3]; >> exp(a) ans = 2.7183 7.3891 20.0855 >> log(a) ans = 0 0.6931 >> sqrt(a) ans = 1.00001.09861.41421.7321 n- >> a = [1 2 3] >> a .^ 2 ans = 1 4 9>> a = [-0.4 1.2 0.6 -1.3] a= -0.4000 1.2000 0.6000 -1.3000 >> abs(a) ans = 0.4000 >> floor(a) ans = -1 1 >> ceil(a) ans = 0 2 1.20000.6000 1.3000 0-2 1-1 ! n- ^ a^3 36 37. MATLAB Programming = (1 , 2 , ), c , + = + = ( + 1 , + 2 , + ) = (1 , 2 , ) = ( 1 , 2 , ) = = ( 1 , 2 , ) / = (1 /, 2 / , /) ./ = (/1 , /2 , / )>> a*c ans = 5>> a = [1 2 3 4]; >> c = 5; >> a + c ans = 6 >> a c ans = -4 >> c a ans = 47-338-229-11101520>> c*a ans = 5101520>> a/c ans = 0.20000.40000.60000.8000>> c./a ans = 5.00002.50001.66671.250037 38. MATLAB Programming , >> x = [-1 0 1] >> y = [3 4 5] >> x + y ans = 246 >> x-y ans = -4 -4 -4 >> cross(x, y) ans = -4 8 4>> x * y ans = -3 4 -5 00 0 34 5 >> x .* y ans = -3 0 5 >> dot(x, y) ans = 2 = >> x ./ y ans = -0.3333 0 0.200038 39. MATLAB Programming , : , , , , , >> x = [5 3 8 4]; >> min(x) ans = 3 >> max(x) ans = 8 >> sum(x) ans = 20>> mean(x) ans = 5>> var(x) ans = 4.6667 >> std(x) ans = 2.160239 40. MATLAB ProgrammingQuiz 6 1 , . 6 1 9883898989929787 1) 2) 3) 4) 78869196 40 41. MATLAB ProgrammingQuiz Sol. 6 1 , . 988389898992978778869196>> s1 = [98 83 89 89]; >> s2 = [89 92 97 87]; >> s3 = [78 86 91 96]; 1) >> (s1+s2+s3)/3 2) >> sum(s1) >> mean(s1) 3) >> max(s1) 4) >> sum(s1+s2+s3) >> sum(s1+s2+s3) / 12 >> (mean(s1)+mean(s2)+mean(s3))/341 42. MATLAB Programming x 10 >> x = linspace(1,100,10) x= 1 12 23 34 4556677889 100 3~6 () >> x(3:6) x= 23Colon Operator 344556 1, 5, 7 () >> x( [1 5 7] ) x= 1 45 67 3, 7~9 >> x( [3 7:9] ) x= 23 67788942 43. MATLAB Programming x 10 >> x = linspace(1,100,10) x= 1 12 23 34 4556677889 100 3 10 >> x(3) = 10 x= 1 1210344556677889 100 5:7 -5 >> x(5:7) = -5 x= 1 12 1034-5-5-57889 100 3, 7~9 105 >> x([3 7:9]) = 105 x= 1 12 105 34-5-5 105 105 105 100 6~8 100, 200, 300 >> x(6:8) = [100 200 300] x= 1 12 105 34 -5 100 200 300 105 100 ! , 43 44. MATLAB ProgrammingQuiz 1 10 10 x , x x . , x = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) , 2 10-2, 4 10-4, 10 10-10 , (1, 8, 3, 6, 5, 4, 7, 2, 9, 0) . : Colon operator, max , , 44 45. MATLAB ProgrammingQuiz Sol. 1 10 10 x , x x . , x = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) , 2 10-2, 4 10-4, 10 10-10 , (1, 8, 3, 6, 5, 4, 7, 2, 9, 0) . : Colon operator, max , , >> x = 1:10 x= 1 2 3 4 5 6 7 >> x(2:2:10) = max(x) x(2:2:10) x= 1 8 3 6 5 4 78910290 45 46. MATLAB Programming x = [1 2 3], y = [4 5], z = [6 7] , [1 2 3 4 5 6 7] ? >> x = [1 2 3]; >> y = [4 5]; >> z = [6 7]; >> [x y z] ans = 1 2 3 ! 456 , 7 [ 6] MATLAB [x y x] . [x y] . , (column) . >> x = [1; 2; 3]; >> y = [4; 5]; >> [x; y] ans = 1 2 3 4 546 47. MATLAB Programming (Matrix)47 48. MATLAB Programming (Matrix) ? : 1 x n : n x 1 48 49. MATLAB Programming2 , (;) = = (2 x 3 ) M= 2 61 34 5>> M = [2 1 4; 6 3 5] (3 x 2 ) >> M = [2 3; 4 6; 5 1] M= 2 4 53 6 149 50. MATLAB Programming 2 = < 1> >> M = [2 1 4] M= 2 1 4 >> M = [M; 6 3 5] M= 2 1 4 6 3 5 >> M = [A; 7 3 9] M= 2 1 4 6 3 5 7 3 9 < 2> >> M = [ [2 1 4]; [6 3 5]; [7 3 9] ] < 3> >> r1 = [2 1 4]; >> r2 = [6 3 5]; >> r3 = [7 3 9]; >> M = [ r1; r2; r3 ]50 51. MATLAB Programming zeros, ones, eye, rand, randn zeros( m, n ) 0 m x n ones( m, n ) 1 m x n eye( m ) 1 m x m rand( m, n )0~1 uniform m x n randn( m, n )0~1 normal m x n magic( m ) m x m 51 52. MATLAB Programming [ 7] , m n . >> zeros(4, 3) >> ones(5, 3) >> eye(6) >> rand(3,5) >> randn(5,7)52 53. MATLAB Programming 1 =