ncuma_函數畫圖.pptx

NCU MCL
NCU MCLSoftware Developer à NCU MCL
函數畫圖
1
簡要 python 學習講義
畫圖步驟 (一)
1. 使用 pylab 套件畫圖:import pylab
2. 設定函式:
def f(x) :
return pylab.sin(2*x) + pylab.sqrt(x)
def g(x) :
return x**3 - 2*x + pylab.cos(x/3)
def h(x) :
return pylab.sin( exp(x) )
2
國立中央大學數學系
畫圖步驟 (二)
def s(x) :
return pylab.log(x) + 2 * pylab.log10(x)
def t(x) :
return pylab.sin( pylab.sqrt( abs(5*x) ) ) )
def u(x) :
return pylab.maximum(pylab.sin(x),pylab.cos(x)**2)
def v(x) :
return pylab.minimum(pylab.sin(x),pylab.cos(2*x))
3
國立中央大學數學系
畫圖步驟 (三)
3. 設定畫圖區間 [a,b] 與點數 n :
a , b , n = 0 , 10 , 100
a , b , n = -pylab.pi , pylab.pi , 100
pi = pylab.pi
a , b , n = -pi , pi , 100
4. 產生所有 x 座標點於 xs:
xs = pylab.linspace(a,b,n)
5. 產生所有 y 座標於 ys:
ys = f(xs)
ys = g(xs)
4
國立中央大學數學系
畫圖步驟 (四)
6. 輸入 xs 與 ys 畫函數圖:
pylab.plot(xs,ys)
pylab.plot(xs,f(xs))
7. 設定圖形屬性:
pylab.grid():顯示背景格線
pylab.title(’bar’):產生圖形標頭 bar
pylab.xlabel("X"):X 軸字串
pylab.ylabel("Y"):Y 軸字串
8. 儲存圖形於檔案:
pylab.savefig(’foo.jpg’)
pylab.savefig(’foo.png’)
9. 顯示圖形於螢幕:
pylab.show()
5
國立中央大學數學系
函數畫圖 : 簡單版 (一)
6
國立中央大學數學系
函數畫圖 : 簡單版 (二)
7
國立中央大學數學系
import pylab
# 設定函式
def f(x) :
return pylab.sin(x) + pylab.cos(2*x)
# 設定 x 範圍 [a,b] 之間,n 為座標點數
a , b , n = 0 , 2*pylab.pi , 100
## 在 [a,b] 之間產生 n 個點存到 xs
xs = pylab.linspace(a,b,n)
## 畫圖:(xs,f(xs))
pylab.plot(xs,f(xs))
## 格線
pylab.grid()
## 螢幕顯示圖形
pylab.show()
 簡單版本:
函數畫圖 : 詳細版 (一)
8
國立中央大學數學系
函數畫圖 : 詳細版 (二)
9
國立中央大學數學系
import pylab
# 設定函式
def f(x) :
return pylab.sin(x) + pylab.cos(2*x)
pi = pylab.pi
# 設定 x 範圍 [a,b] 之間,n 為座標點數
a , b , n = 0 , 2*pi , 100
## 在 [a,b] 之間產生 n 個點存到 xs
xs = pylab.linspace(a,b,n)
## ys 為所有 xs 的 y 值
ys = f(xs)
## 畫紙底色為 white
pylab.figure(facecolor=’w’)
## 畫圖
pylab.plot(xs,ys)
## 顯示背景格線
pylab.grid()
# 設定 X 與 Y 軸
pylab.xlabel("X")
pylab.ylabel("Y")
# 設定標頭
pylab.title("sin(x)+cos(2x)")
## 螢幕顯示圖形
pylab.show()
 詳細版本:
1 sur 9

Recommandé

Ppt 127-135 par
Ppt 127-135Ppt 127-135
Ppt 127-135hungchiayang1
1.5K vues9 diapositives
Ppt 127-135 par
Ppt 127-135Ppt 127-135
Ppt 127-135hungchiayang1
39 vues9 diapositives
函數微分_範例.pptx par
函數微分_範例.pptx函數微分_範例.pptx
函數微分_範例.pptxmclmath
40 vues5 diapositives
ncuma_函數微分計算.pptx par
ncuma_函數微分計算.pptxncuma_函數微分計算.pptx
ncuma_函數微分計算.pptxNCU MCL
2.2K vues5 diapositives
Ppt 136-140 par
Ppt 136-140Ppt 136-140
Ppt 136-140hungchiayang1
270 vues5 diapositives
Ppt 138-142 par
Ppt 138-142Ppt 138-142
Ppt 138-142hungchiayang1
8.4K vues5 diapositives

Contenu connexe

Similaire à ncuma_函數畫圖.pptx

Appendix B 教學 par
Appendix B 教學Appendix B 教學
Appendix B 教學hungchiayang1
315 vues9 diapositives
Sym py edu par
Sym py eduSym py edu
Sym py eduAlisha Smile
4.6K vues39 diapositives
Appendix B par
Appendix BAppendix B
Appendix BAlisha Smile
21 vues12 diapositives
ncuma_Taylor 多項式.pptx par
ncuma_Taylor 多項式.pptxncuma_Taylor 多項式.pptx
ncuma_Taylor 多項式.pptxNCU MCL
33 vues6 diapositives
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫 par
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫Justin Lin
11K vues59 diapositives
Ch11 範例 par
Ch11 範例Ch11 範例
Ch11 範例hungchiayang1
832 vues15 diapositives

Plus de NCU MCL

函數畫圖_習題4.pptx par
函數畫圖_習題4.pptx函數畫圖_習題4.pptx
函數畫圖_習題4.pptxNCU MCL
229 vues1 diapositive
數值積分法_3.pptx par
數值積分法_3.pptx數值積分法_3.pptx
數值積分法_3.pptxNCU MCL
679 vues1 diapositive
數值積分法_2.pptx par
數值積分法_2.pptx數值積分法_2.pptx
數值積分法_2.pptxNCU MCL
40 vues1 diapositive
數值積分法_1.pptx par
數值積分法_1.pptx數值積分法_1.pptx
數值積分法_1.pptxNCU MCL
46 vues1 diapositive
數值求根習題_1.pptx par
數值求根習題_1.pptx數值求根習題_1.pptx
數值求根習題_1.pptxNCU MCL
82 vues1 diapositive
函數微分習題_3.pptx par
函數微分習題_3.pptx函數微分習題_3.pptx
函數微分習題_3.pptxNCU MCL
526 vues3 diapositives

Plus de NCU MCL(20)

函數畫圖_習題4.pptx par NCU MCL
函數畫圖_習題4.pptx函數畫圖_習題4.pptx
函數畫圖_習題4.pptx
NCU MCL229 vues
數值積分法_3.pptx par NCU MCL
數值積分法_3.pptx數值積分法_3.pptx
數值積分法_3.pptx
NCU MCL679 vues
數值積分法_2.pptx par NCU MCL
數值積分法_2.pptx數值積分法_2.pptx
數值積分法_2.pptx
NCU MCL40 vues
數值積分法_1.pptx par NCU MCL
數值積分法_1.pptx數值積分法_1.pptx
數值積分法_1.pptx
NCU MCL46 vues
數值求根習題_1.pptx par NCU MCL
數值求根習題_1.pptx數值求根習題_1.pptx
數值求根習題_1.pptx
NCU MCL82 vues
函數微分習題_3.pptx par NCU MCL
函數微分習題_3.pptx函數微分習題_3.pptx
函數微分習題_3.pptx
NCU MCL526 vues
SymPy 在微積分上的應用_3.pptx par NCU MCL
SymPy 在微積分上的應用_3.pptxSymPy 在微積分上的應用_3.pptx
SymPy 在微積分上的應用_3.pptx
NCU MCL27 vues
SymPy 在微積分上的應用_2.pptx par NCU MCL
SymPy 在微積分上的應用_2.pptxSymPy 在微積分上的應用_2.pptx
SymPy 在微積分上的應用_2.pptx
NCU MCL26 vues
SymPy 在微積分上的應用_1.pptx par NCU MCL
SymPy 在微積分上的應用_1.pptxSymPy 在微積分上的應用_1.pptx
SymPy 在微積分上的應用_1.pptx
NCU MCL30 vues
極座標畫圖_3.pptx par NCU MCL
極座標畫圖_3.pptx極座標畫圖_3.pptx
極座標畫圖_3.pptx
NCU MCL12 vues
極座標畫圖_2.pptx par NCU MCL
極座標畫圖_2.pptx極座標畫圖_2.pptx
極座標畫圖_2.pptx
NCU MCL15 vues
極座標畫圖_1.pptx par NCU MCL
極座標畫圖_1.pptx極座標畫圖_1.pptx
極座標畫圖_1.pptx
NCU MCL12 vues
Taylor 多項式_3.pptx par NCU MCL
Taylor 多項式_3.pptxTaylor 多項式_3.pptx
Taylor 多項式_3.pptx
NCU MCL7 vues
Taylor 多項式_2.pptx par NCU MCL
Taylor 多項式_2.pptxTaylor 多項式_2.pptx
Taylor 多項式_2.pptx
NCU MCL10 vues
Taylor 多項式_1.pptx par NCU MCL
Taylor 多項式_1.pptxTaylor 多項式_1.pptx
Taylor 多項式_1.pptx
NCU MCL8 vues
微分方程式求解_3.pptx par NCU MCL
微分方程式求解_3.pptx微分方程式求解_3.pptx
微分方程式求解_3.pptx
NCU MCL38 vues
微分方程式求解_2.pptx par NCU MCL
微分方程式求解_2.pptx微分方程式求解_2.pptx
微分方程式求解_2.pptx
NCU MCL28 vues
微分方程式求解_1.pptx par NCU MCL
微分方程式求解_1.pptx微分方程式求解_1.pptx
微分方程式求解_1.pptx
NCU MCL22 vues
牛頓迭代法_3.pptx par NCU MCL
牛頓迭代法_3.pptx牛頓迭代法_3.pptx
牛頓迭代法_3.pptx
NCU MCL18 vues
牛頓迭代法_2.pptx par NCU MCL
牛頓迭代法_2.pptx牛頓迭代法_2.pptx
牛頓迭代法_2.pptx
NCU MCL16 vues

ncuma_函數畫圖.pptx

  • 2. 畫圖步驟 (一) 1. 使用 pylab 套件畫圖:import pylab 2. 設定函式: def f(x) : return pylab.sin(2*x) + pylab.sqrt(x) def g(x) : return x**3 - 2*x + pylab.cos(x/3) def h(x) : return pylab.sin( exp(x) ) 2 國立中央大學數學系
  • 3. 畫圖步驟 (二) def s(x) : return pylab.log(x) + 2 * pylab.log10(x) def t(x) : return pylab.sin( pylab.sqrt( abs(5*x) ) ) ) def u(x) : return pylab.maximum(pylab.sin(x),pylab.cos(x)**2) def v(x) : return pylab.minimum(pylab.sin(x),pylab.cos(2*x)) 3 國立中央大學數學系
  • 4. 畫圖步驟 (三) 3. 設定畫圖區間 [a,b] 與點數 n : a , b , n = 0 , 10 , 100 a , b , n = -pylab.pi , pylab.pi , 100 pi = pylab.pi a , b , n = -pi , pi , 100 4. 產生所有 x 座標點於 xs: xs = pylab.linspace(a,b,n) 5. 產生所有 y 座標於 ys: ys = f(xs) ys = g(xs) 4 國立中央大學數學系
  • 5. 畫圖步驟 (四) 6. 輸入 xs 與 ys 畫函數圖: pylab.plot(xs,ys) pylab.plot(xs,f(xs)) 7. 設定圖形屬性: pylab.grid():顯示背景格線 pylab.title(’bar’):產生圖形標頭 bar pylab.xlabel("X"):X 軸字串 pylab.ylabel("Y"):Y 軸字串 8. 儲存圖形於檔案: pylab.savefig(’foo.jpg’) pylab.savefig(’foo.png’) 9. 顯示圖形於螢幕: pylab.show() 5 國立中央大學數學系
  • 6. 函數畫圖 : 簡單版 (一) 6 國立中央大學數學系
  • 7. 函數畫圖 : 簡單版 (二) 7 國立中央大學數學系 import pylab # 設定函式 def f(x) : return pylab.sin(x) + pylab.cos(2*x) # 設定 x 範圍 [a,b] 之間,n 為座標點數 a , b , n = 0 , 2*pylab.pi , 100 ## 在 [a,b] 之間產生 n 個點存到 xs xs = pylab.linspace(a,b,n) ## 畫圖:(xs,f(xs)) pylab.plot(xs,f(xs)) ## 格線 pylab.grid() ## 螢幕顯示圖形 pylab.show()  簡單版本:
  • 8. 函數畫圖 : 詳細版 (一) 8 國立中央大學數學系
  • 9. 函數畫圖 : 詳細版 (二) 9 國立中央大學數學系 import pylab # 設定函式 def f(x) : return pylab.sin(x) + pylab.cos(2*x) pi = pylab.pi # 設定 x 範圍 [a,b] 之間,n 為座標點數 a , b , n = 0 , 2*pi , 100 ## 在 [a,b] 之間產生 n 個點存到 xs xs = pylab.linspace(a,b,n) ## ys 為所有 xs 的 y 值 ys = f(xs) ## 畫紙底色為 white pylab.figure(facecolor=’w’) ## 畫圖 pylab.plot(xs,ys) ## 顯示背景格線 pylab.grid() # 設定 X 與 Y 軸 pylab.xlabel("X") pylab.ylabel("Y") # 設定標頭 pylab.title("sin(x)+cos(2x)") ## 螢幕顯示圖形 pylab.show()  詳細版本: