1 / 37

微積分 第三次上機 Matlab 教學

微積分 第三次上機 Matlab 教學. 2007/12/04 朱育正. Outline. Matlab 之基本操作 向量與矩陣運算 2D 繪圖 微分運算 實作. Matlab 之基本操作. Matlab 之基本操作. Clear : 去除所有定義過的變數名稱。. Matlab 之簡易數學. Matlab 變數的名稱大小寫有分。所以 x 和 X 將會不同 有些 Matlab 內定的變數盡量不拿來當變數. Matlab 之 簡易數學. 基本運算 : 加( Addition ) : + 減( Sudtraction ) : -

signa
Download Presentation

微積分 第三次上機 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. 微積分 第三次上機Matlab 教學 2007/12/04 朱育正

  2. Outline • Matlab之基本操作 • 向量與矩陣運算 • 2D繪圖 • 微分運算 • 實作

  3. Matlab之基本操作

  4. Matlab之基本操作 • Clear: 去除所有定義過的變數名稱。

  5. Matlab之簡易數學 • Matlab 變數的名稱大小寫有分。所以x和X將會不同 • 有些Matlab內定的變數盡量不拿來當變數

  6. Matlab之簡易數學 • 基本運算: • 加(Addition):+ • 減(Sudtraction):- • 乘(Multiplication):* • 除(Division): /or \ (如:21.9/3or 3\21.9) • 次方(Exponentiation): ^ (如:34=3^4) • 絕對值:abs (如:abs(-1)) • 開根號:sqrt

  7. 基本數學函數 • 三角函數:sin(t) • 反三角函數:asin(t) • 自然指數:exp(t) • 自然對數:log(t) • 以10為底對數:log10(t)

  8. 向量與矩陣運算—宣告矩陣

  9. 向量與矩陣運算—矩陣乘法 矩陣計算時要注意 維度相不相同 a * b 一般的矩陣乘法 a .* b 代表相同長度陣列中 相對應的元素相乘

  10. 2D繪圖指令--plot • plot (橫軸變數,縱軸變數)

  11. 2D繪圖指令 • xlabel(‘name ‘) :x軸名稱 • ylabel(‘name’) :y軸名稱 • title(‘name’) :圖表名稱

  12. 微分運算-梯度與微分的運算

  13. 微分運算-梯度與微分的運算 • >>x=0:2:8 • x= • 0 2 4 6 8 • >>y=sqrt(x) • y= • 0 1.4142 2.0000 2.4495 2.8284

  14. 微分運算-梯度與微分的運算 • >>gradient(y,x) • ans = • 0.7071 0.5000 0.2588 0.2071 0.1895 • y在x=0時,斜率為0.7071 • y在x=2時,斜率為0.5000 • y在x=4時,斜率為0.2588 • y在x=6時,斜率為0.2071 • y在x=8時,斜率為0.1895

  15. 微分運算-梯度與微分的運算 • >>x=linspace(0,2*pi,36); • >>y=sin(x); • >>dy=gradient(y,2*pi,36); • >>plot(x,y,x,dy);legend('sin(x)','d sin(x)/dx') • >> Interp1(x,dy,2,'spline') • >>cos(2)

  16. 微分運算-梯度與微分的運算

  17. 微分運算-梯度與微分的運算

  18. 微分運算-梯度與微分的運算 • plot(x,y,x,dy,x,cos(x));legend('sin(x)','d sin(x)/dx','cos(x)')

  19. 微分運算-差分運算

  20. 微分運算-差分運算 • >>diff([3 5 9 4 1]) • ans = • 2 4 -5 -3 • >>x=0:0.2:6; • >>y=x.*sin(x); • >>dy=diff(y)./diff(x); • >>plot(x,y,x(1:end-1),dy);legend('y(x)','dy/dx')

  21. 微分運算-差分運算 >> plot(x,dyt,x(1:end-1),dy);legend('exact','approx') >>dy2 = gradient(y,0.2); >>plot(x,dyt,x,dy);legend('exact','approx')

  22. 微分運算-差分運算

  23. 微分運算-差分運算

  24. 微分運算-微分與差分差別

  25. 微分運算-微分與差分差別

  26. 微分與差分差別 • 可觀察到gradient所計算出的微分值 • 較差分法所計算而得的微分來的準確

  27. 上次實作

  28. 實作  • Midterm第一題 • 利用limit function • 並畫出其圖形 • 將檔案宣告成自己的學號 • A班的檔名 • A+學號 • 例如: • A96325122_lab3 • B班的檔名 • B+學號 • 例如: • B96325122_lab3

  29. Reference • MATLAB7 程式設計 • 洪維恩著 • 旗標出版股份有限公司

  30. 實作答案

  31. 實作

More Related