1 / 81

第 1 章 綜觀 MATLAB

第 1 章 綜觀 MATLAB. Text book. Introduction to Matlab 6 for Engineering William J. Palm III Mc Graw Hill Matlab 6 在工程上的應用 -Matlab 6.5 Update 呂明和 黃逸群 譯 普林斯頓國際有限公司 CG 001. user:. Program Langage. Matlab ( 大小寫是有區分的 !) Fortran C++ Virtual Basic Cobol Pascal …. windows.

hea
Download Presentation

第 1 章 綜觀 MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第1章 綜觀MATLAB Puff! The magic dragon, live by the sea.

  2. Text book • Introduction to Matlab 6 for Engineering • William J. Palm III • Mc Graw Hill • Matlab 6在工程上的應用-Matlab 6.5 Update • 呂明和 黃逸群 譯 • 普林斯頓國際有限公司 CG 001 Puff! The magic dragon, live by the sea.

  3. user: Program Langage • Matlab (大小寫是有區分的!) • Fortran • C++ • Virtual Basic • Cobol • Pascal • … Puff! The magic dragon, live by the sea.

  4. windows • Launch pad window 啟動台視窗 • Command window 命令視窗 • Command history window 命令記錄視窗 • Editor/Debugger window • Graph window • Tool bar • Current directory Puff! The magic dragon, live by the sea.

  5. Puff! The magic dragon, live by the sea.

  6. Puff! The magic dragon, live by the sea.

  7. Order of precedence • P.10 examples • P.11 T1.1-1 Puff! The magic dragon, live by the sea.

  8. P.11 T1.1-1 • (a) 6+10/13+18/(5*7)+5*9^2 • (b) 6*(35^(1/4))+14^0.35 Puff! The magic dragon, live by the sea.

  9. format short • 1/7 • format long • 1/7 • help • demo Puff! The magic dragon, live by the sea.

  10. Puff! The magic dragon, live by the sea.

  11. The assignment operator (指定運算子) or replacement operator (替換運算子) • x=3 ~ x3 • x=x+2 ~ xx+2 • Error expression 6=x • x=6 is the right expression • What about x=5+y ~ x5+y Puff! The magic dragon, live by the sea.

  12. 國中應用問題 p.12 • pie=3.1416; • r=8; • h=15; • V=pie*r^2*h; • V=V+0.20*V; • r=sqrt(V/(pie*h)) • ans= Puff! The magic dragon, live by the sea.

  13. Variable names • <32 characters; begin with alpha.. • e.g. right expression: speed_12345 wrong expression: 1aaaaa Puff! The magic dragon, live by the sea.

  14. Puff! The magic dragon, live by the sea.

  15. whos (暫存變數) • x=2; y=6+x; x=y+7 • x=2; x=2, y=8; x=15, y=8 • who • whos • whos x • Exist (‘var1’) ~ 1 in use, 0 not exist Puff! The magic dragon, live by the sea.

  16. Long statement … • See (p.13) Puff! The magic dragon, live by the sea.

  17. for previous statement modification • , , tab Puff! The magic dragon, live by the sea.

  18. Smart recall • volume=3*5 • vol + Puff! The magic dragon, live by the sea.

  19. editing • Del, backspace • Ctrl+k, Esc ~ clear all line • Clear ~ clear all variables • Clear var1, var2,.. ~ clear the 2 variables • Kill Puff! The magic dragon, live by the sea.

  20. Puff! The magic dragon, live by the sea.

  21. Complex operation • P.16, s=3+7i; w=5-9i; w+s w*s w/s Puff! The magic dragon, live by the sea.

  22. Menus & the toolbar • The desktop menus • The File Menu in Matlab 6 set path • The Edit Menu in Matlab 6 Puff! The magic dragon, live by the sea.

  23. Computing with Matlab • Arrays 內建函數 sin(x), cos(x), log(x), log10(x), exp(x), asin(x). Puff! The magic dragon, live by the sea.

  24. Computing with Matlab • x=[0 1 3 6]; y=[6 3 1 0]; z=x+y=[6 4 4 6] • u=[0:.1:10]; w=5*sin(u); u(7) w(7) length(w) length(u) Puff! The magic dragon, live by the sea.

  25. Puff! The magic dragon, live by the sea.

  26. Polynomial roots • a=[1 –7 40 –34]; roots(a) • r=[1, 3+5i, 3-5i]; poly(r) • or poly([1, 3+5i, 3-5i]) • See also fzero(.) Puff! The magic dragon, live by the sea.

  27. Self testing • u=[cos(0): 0.02: log10(100)] length(u) u(25) • a=[1 6 -11 290] r=roots(a) b=poly(r) • Check a & b, are they the same? Puff! The magic dragon, live by the sea.

  28. Puff! The magic dragon, live by the sea.

  29. Working with files • I/O • Set path… /homework/ • problem1.m • Is ‘problem1’ a variable? • Is ‘problem1’ a pre-constructed command? • Is problem1.m in the present directory? • Find it in the search path directory! Puff! The magic dragon, live by the sea.

  30. Show the present working directory & *.m files • pwd • dir C:\MATLAB\BIN • what C:\MATLAB\BIN • pathtool • add path • rmpath Puff! The magic dragon, live by the sea.

  31. Puff! The magic dragon, live by the sea.

  32. Relational operators • x=[6 3 9] • y=[14 2 9] • z=(x<y) • z=(x~=y) • z=(x==y) • z=x(x>8) • Boolean operator (‘yes’=1, ‘no’=0) Puff! The magic dragon, live by the sea.

  33. Relational operators • x=[6 3 9 11] • y=[14 2 9 13] • z=x(x<y) • 找出陣列x中每一個小於陣列y中相對元素所的相對元素, 所得的陣列z=[6, 11] Puff! The magic dragon, live by the sea.

  34. 找出陣列中不為零的元素的索引值 • x=[-2, 0, 4] • y=find(x) • y=[1 3] Puff! The magic dragon, live by the sea.

  35. 比較 • x=[6 3 9 11]; y=[14 2 9 13] • z1=x(x<y); z2=y(x<y); z3=find(x<y); • z1 • z2 • z3 • Length(z3) • z1, z2 give the values; while z3 give the indices Puff! The magic dragon, live by the sea.

  36. Example p.26 • A=[55, 62, 60, 61, 63, 65, 62, 59, 58, 56]; • B=[54, 59, 62, 64, 68, 68, 62, 59, 57, 53]; • when=find(A>60) • how_many1=length(when) • above=A(A>B) • how_many1=length(above) Puff! The magic dragon, live by the sea.

  37. Self testing p.27 • Test by your own, not by computer! Puff! The magic dragon, live by the sea.

  38. plot • x=[0: 0.01:10]; • y=sin(2*x); • plot(x,y), xlabel(‘x’), ylabel(‘sin(2x)’) • Use help plot to understand the above statement! See also plot, label, title, gtext • Graphic window Puff! The magic dragon, live by the sea.

  39. Overlay plot 重疊繪圖 • x=[0: .01: 5]; • y=2*sqrt(x); • z=4*sin(3*x); • plot(x,y,x,z), xlabel('x'), gtext('y'), gtext('z') • gtext ~ 指定好游標位置按下滑鼠鍵, 以放置gtext所要放置的文字 • [u,v]=ginput(n) ~滑鼠點下的n個位置座標 Puff! The magic dragon, live by the sea.

  40. Overlay plot 重疊繪圖 • x=[0: .01: 5]; • y=2*sqrt(x); • z=4*sin(3*x); • plot(x,y,x,z), xlabel('x'), gtext('y'), gtext('z') • [u,v]=ginput(n) Puff! The magic dragon, live by the sea.

  41. data marker • x=[15: 2: 23]; • y=[20 50 60 90 70]; • plot(x,y,’+’,x,y), xlabel(‘x (seconds)’), ylabel(‘y (volts)’) Puff! The magic dragon, live by the sea.

  42. Plotting Polynomials • a=[9, -5, 3, 7]; • x=[-2: .01:5]; • f=polyval(a,x); • plot(x,f), xlabel('x'), ylabel('f(x)'), grid • f(x)=9x^3-5x^2+3x+7 • find f(0), f(2), …,f(10) Puff! The magic dragon, live by the sea.

  43. Puff! The magic dragon, live by the sea.

  44. Puff! The magic dragon, live by the sea.

  45. Self testing p.31 • Write down the statements on a blank paper, and try to use your brain & this book to ‘run’ this program! Puff! The magic dragon, live by the sea.

  46. Linear Algebraic Equations 6x+12y+4z=70 7x-2y+3z=5 2x+8y-9z=64 Ax=Bx=A\B • A=[6,12,4; 7,-2,3; 2,8,-9]; • B=[70; 5; 64]; • A\B • A/B Puff! The magic dragon, live by the sea.

  47. Linear Algebraic Equations 6x+12y+4z=70 7x-2y+3z=5 2x+8y-9z=64 Ax=Bx=A-1B therefore we use A\B • A=[6,12,4; 7,-2,3; 2,8,-9]; 3 by 3 • B=[70; 5; 64]; 3 by 1 • A\B • A/B Puff! The magic dragon, live by the sea.

  48. Self testing p.32 Puff! The magic dragon, live by the sea.

  49. Other functions • Statistics • Numerical analysis & Differential equations • Symbolic Processing Puff! The magic dragon, live by the sea.

  50. Script files & the Editor/Debugger • 1. Direct command ~ 互動模式 • 2. Script files Puff! The magic dragon, live by the sea.

More Related