ncuma_牛頓法.pptx

NCU MCL
NCU MCLSoftware Developer at NCU MCL
數值求根法 :牛頓迭代法 (一)
 求根步驟:
1. 設定容許誤差 tol > 0
2. 猜測起始近似根為 a
3. 計算 f(a) 與 f’(a)
4. 計算 b = a −
5. 如果 |f(b)| < tol ,則 b 為近似根,輸出 b 後停止計算
6. 更新 a = b ,回到步驟 3
1
國立中央大學數學系
 不良的起始近似根 a 可能造成求根步驟無法收斂,此時要變更起始近似根。
起始近似根可透過函數圖形來估算。
2
數值求根法 :牛頓迭代法 (二)
 以上兩種求根法是否收斂都跟起始設定有關,二分逼近法起始求根範圍
(a,b) 如果不滿足 f(a)f(b) < 0,則演算步驟不成立。牛頓法的起
始根 a 若不靠近函數根 r ,往往造成近似根不收斂。為了確保兩個方
法都能收斂,可先用畫圖法畫出函數圖形,由中觀察根的大概位置,然
後找出二分逼近法的起始範圍 (a,b) 或是牛頓法的起始點 a 。
一般來說,二分逼近法是最緩慢的求根法,牛頓求根法的收斂速度則是
相當快,幾次迭代就可快速逼近函數根。
 本程式利用函式來設定求根函數與其一次微分函數,此範例的求根函數為
f(x) = − 2,函數根 r 為 ,一次微分則為 f(x) = 2x 。
函數根 r 用來計算根的誤差,決定近似根的品質。兩種求根法都以近似
根的函數值是否小於容忍值 tol 來決定是否跳離迴圈結束迭代。
國立中央大學數學系
3
import math
# 函數 : x**2 - 2 與一次微分: 2x
def f(x) : x**2 - 2
def df(x) : 2*x
# 根
r = math.sqrt(2)
# 牛頓迭代法
a , k , tol = 2 , 0 , 1.e-14
err = abs(a-r)
print( "> 牛頓迭代法:" )
print( "{:<2} : {:<10e} {:<10e}".format(k,a,err) , sep="" )
while True :
b = a - f(a)/df(a)
err = abs(b-r)
k += 1
# 迭代次數 近似根 誤差,以下 10e 代表以 10 格與科學記號呈現數字
print( "{:<2} : {:<10e} {:<10e}".format(k,b,err) , sep="" )
# 函數絕對值小於 tol 才跳離迭代
if abs(f(b)) < tol : break
a = b
數值求根法 :牛頓迭代法 (三)
國立中央大學數學系
4
程式輸出:
> 牛頓迭代法:
0 : 2.000000e+00 5.857864e-01
1 : 1.500000e+00 8.578644e-02
2 : 1.416667e+00 2.453104e-03
3 : 1.414216e+00 2.123901e-06
4 : 1.414214e+00 1.594724e-12
5 : 1.414214e+00 0.000000e+00
數值求根法 :牛頓迭代法 (四)
國立中央大學數學系
1 of 4

Recommended

Ppt 152-155 by
Ppt 152-155Ppt 152-155
Ppt 152-155hungchiayang1
803 views4 slides
Ppt 141-149 by
Ppt 141-149Ppt 141-149
Ppt 141-149hungchiayang1
49 views9 slides
二分逼近法_範例.pptx by
二分逼近法_範例.pptx二分逼近法_範例.pptx
二分逼近法_範例.pptxmclmath
51 views5 slides
ncuma_數值求根法.pptx by
ncuma_數值求根法.pptxncuma_數值求根法.pptx
ncuma_數值求根法.pptxNCU MCL
140 views5 slides
Ppt 145-149 by
Ppt 145-149Ppt 145-149
Ppt 145-149hungchiayang1
1.2K views5 slides
函數畫圖_習題4.pptx by
函數畫圖_習題4.pptx函數畫圖_習題4.pptx
函數畫圖_習題4.pptxNCU MCL
279 views1 slide

More Related Content

More from NCU MCL

數值積分法_1.pptx by
數值積分法_1.pptx數值積分法_1.pptx
數值積分法_1.pptxNCU MCL
55 views1 slide
數值求根習題_1.pptx by
數值求根習題_1.pptx數值求根習題_1.pptx
數值求根習題_1.pptxNCU MCL
83 views1 slide
函數微分習題_3.pptx by
函數微分習題_3.pptx函數微分習題_3.pptx
函數微分習題_3.pptxNCU MCL
529 views3 slides
SymPy 在微積分上的應用_3.pptx by
SymPy 在微積分上的應用_3.pptxSymPy 在微積分上的應用_3.pptx
SymPy 在微積分上的應用_3.pptxNCU MCL
27 views2 slides
SymPy 在微積分上的應用_2.pptx by
SymPy 在微積分上的應用_2.pptxSymPy 在微積分上的應用_2.pptx
SymPy 在微積分上的應用_2.pptxNCU MCL
26 views2 slides
SymPy 在微積分上的應用_1.pptx by
SymPy 在微積分上的應用_1.pptxSymPy 在微積分上的應用_1.pptx
SymPy 在微積分上的應用_1.pptxNCU MCL
30 views1 slide

More from NCU MCL(20)

數值積分法_1.pptx by NCU MCL
數值積分法_1.pptx數值積分法_1.pptx
數值積分法_1.pptx
NCU MCL55 views
數值求根習題_1.pptx by NCU MCL
數值求根習題_1.pptx數值求根習題_1.pptx
數值求根習題_1.pptx
NCU MCL83 views
函數微分習題_3.pptx by NCU MCL
函數微分習題_3.pptx函數微分習題_3.pptx
函數微分習題_3.pptx
NCU MCL529 views
SymPy 在微積分上的應用_3.pptx by NCU MCL
SymPy 在微積分上的應用_3.pptxSymPy 在微積分上的應用_3.pptx
SymPy 在微積分上的應用_3.pptx
NCU MCL27 views
SymPy 在微積分上的應用_2.pptx by NCU MCL
SymPy 在微積分上的應用_2.pptxSymPy 在微積分上的應用_2.pptx
SymPy 在微積分上的應用_2.pptx
NCU MCL26 views
SymPy 在微積分上的應用_1.pptx by NCU MCL
SymPy 在微積分上的應用_1.pptxSymPy 在微積分上的應用_1.pptx
SymPy 在微積分上的應用_1.pptx
NCU MCL30 views
極座標畫圖_3.pptx by NCU MCL
極座標畫圖_3.pptx極座標畫圖_3.pptx
極座標畫圖_3.pptx
NCU MCL12 views
極座標畫圖_2.pptx by NCU MCL
極座標畫圖_2.pptx極座標畫圖_2.pptx
極座標畫圖_2.pptx
NCU MCL15 views
極座標畫圖_1.pptx by NCU MCL
極座標畫圖_1.pptx極座標畫圖_1.pptx
極座標畫圖_1.pptx
NCU MCL12 views
Taylor 多項式_3.pptx by NCU MCL
Taylor 多項式_3.pptxTaylor 多項式_3.pptx
Taylor 多項式_3.pptx
NCU MCL8 views
Taylor 多項式_2.pptx by NCU MCL
Taylor 多項式_2.pptxTaylor 多項式_2.pptx
Taylor 多項式_2.pptx
NCU MCL10 views
Taylor 多項式_1.pptx by NCU MCL
Taylor 多項式_1.pptxTaylor 多項式_1.pptx
Taylor 多項式_1.pptx
NCU MCL8 views
微分方程式求解_3.pptx by NCU MCL
微分方程式求解_3.pptx微分方程式求解_3.pptx
微分方程式求解_3.pptx
NCU MCL39 views
微分方程式求解_2.pptx by NCU MCL
微分方程式求解_2.pptx微分方程式求解_2.pptx
微分方程式求解_2.pptx
NCU MCL29 views
微分方程式求解_1.pptx by NCU MCL
微分方程式求解_1.pptx微分方程式求解_1.pptx
微分方程式求解_1.pptx
NCU MCL22 views
牛頓迭代法_3.pptx by NCU MCL
牛頓迭代法_3.pptx牛頓迭代法_3.pptx
牛頓迭代法_3.pptx
NCU MCL18 views
牛頓迭代法_2.pptx by NCU MCL
牛頓迭代法_2.pptx牛頓迭代法_2.pptx
牛頓迭代法_2.pptx
NCU MCL16 views
牛頓迭代法_1.pptx by NCU MCL
牛頓迭代法_1.pptx牛頓迭代法_1.pptx
牛頓迭代法_1.pptx
NCU MCL28 views
數值求根習題_3.pptx by NCU MCL
數值求根習題_3.pptx數值求根習題_3.pptx
數值求根習題_3.pptx
NCU MCL118 views
數值求根習題_2.pptx by NCU MCL
數值求根習題_2.pptx數值求根習題_2.pptx
數值求根習題_2.pptx
NCU MCL88 views

Recently uploaded

AIoT 智能商店_艾鍗學院-AIoT智能行動服務物聯網班 by
AIoT 智能商店_艾鍗學院-AIoT智能行動服務物聯網班AIoT 智能商店_艾鍗學院-AIoT智能行動服務物聯網班
AIoT 智能商店_艾鍗學院-AIoT智能行動服務物聯網班IttrainingIttraining
43 views25 slides
AI Technology & Development of Civilization by
AI Technology & Development of CivilizationAI Technology & Development of Civilization
AI Technology & Development of Civilizationunclebrown017
41 views74 slides
Hacking Facebook for fun and profit by Pranav Hivarekar by
Hacking Facebook for fun and profit by Pranav HivarekarHacking Facebook for fun and profit by Pranav Hivarekar
Hacking Facebook for fun and profit by Pranav HivarekarPranav Hivarekar
6 views69 slides
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式 by
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式Shengyou Fan
150 views54 slides
商品辨識定位系統_艾鍗學院-AIoT智能行動服務物聯網班 by
商品辨識定位系統_艾鍗學院-AIoT智能行動服務物聯網班商品辨識定位系統_艾鍗學院-AIoT智能行動服務物聯網班
商品辨識定位系統_艾鍗學院-AIoT智能行動服務物聯網班IttrainingIttraining
40 views37 slides
居家雲端照護系統_艾鍗學院-AIoT智能行動服務物聯網班 by
居家雲端照護系統_艾鍗學院-AIoT智能行動服務物聯網班居家雲端照護系統_艾鍗學院-AIoT智能行動服務物聯網班
居家雲端照護系統_艾鍗學院-AIoT智能行動服務物聯網班IttrainingIttraining
43 views32 slides

Recently uploaded(6)

AIoT 智能商店_艾鍗學院-AIoT智能行動服務物聯網班 by IttrainingIttraining
AIoT 智能商店_艾鍗學院-AIoT智能行動服務物聯網班AIoT 智能商店_艾鍗學院-AIoT智能行動服務物聯網班
AIoT 智能商店_艾鍗學院-AIoT智能行動服務物聯網班
AI Technology & Development of Civilization by unclebrown017
AI Technology & Development of CivilizationAI Technology & Development of Civilization
AI Technology & Development of Civilization
unclebrown01741 views
Hacking Facebook for fun and profit by Pranav Hivarekar by Pranav Hivarekar
Hacking Facebook for fun and profit by Pranav HivarekarHacking Facebook for fun and profit by Pranav Hivarekar
Hacking Facebook for fun and profit by Pranav Hivarekar
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式 by Shengyou Fan
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式
[GDG Kaohsiung DevFest 2023] 以 Compose 及 Kotlin Multiplatform 打造多平台應用程式
Shengyou Fan150 views
商品辨識定位系統_艾鍗學院-AIoT智能行動服務物聯網班 by IttrainingIttraining
商品辨識定位系統_艾鍗學院-AIoT智能行動服務物聯網班商品辨識定位系統_艾鍗學院-AIoT智能行動服務物聯網班
商品辨識定位系統_艾鍗學院-AIoT智能行動服務物聯網班
居家雲端照護系統_艾鍗學院-AIoT智能行動服務物聯網班 by IttrainingIttraining
居家雲端照護系統_艾鍗學院-AIoT智能行動服務物聯網班居家雲端照護系統_艾鍗學院-AIoT智能行動服務物聯網班
居家雲端照護系統_艾鍗學院-AIoT智能行動服務物聯網班

ncuma_牛頓法.pptx

  • 1. 數值求根法 :牛頓迭代法 (一)  求根步驟: 1. 設定容許誤差 tol > 0 2. 猜測起始近似根為 a 3. 計算 f(a) 與 f’(a) 4. 計算 b = a − 5. 如果 |f(b)| < tol ,則 b 為近似根,輸出 b 後停止計算 6. 更新 a = b ,回到步驟 3 1 國立中央大學數學系  不良的起始近似根 a 可能造成求根步驟無法收斂,此時要變更起始近似根。 起始近似根可透過函數圖形來估算。
  • 2. 2 數值求根法 :牛頓迭代法 (二)  以上兩種求根法是否收斂都跟起始設定有關,二分逼近法起始求根範圍 (a,b) 如果不滿足 f(a)f(b) < 0,則演算步驟不成立。牛頓法的起 始根 a 若不靠近函數根 r ,往往造成近似根不收斂。為了確保兩個方 法都能收斂,可先用畫圖法畫出函數圖形,由中觀察根的大概位置,然 後找出二分逼近法的起始範圍 (a,b) 或是牛頓法的起始點 a 。 一般來說,二分逼近法是最緩慢的求根法,牛頓求根法的收斂速度則是 相當快,幾次迭代就可快速逼近函數根。  本程式利用函式來設定求根函數與其一次微分函數,此範例的求根函數為 f(x) = − 2,函數根 r 為 ,一次微分則為 f(x) = 2x 。 函數根 r 用來計算根的誤差,決定近似根的品質。兩種求根法都以近似 根的函數值是否小於容忍值 tol 來決定是否跳離迴圈結束迭代。 國立中央大學數學系
  • 3. 3 import math # 函數 : x**2 - 2 與一次微分: 2x def f(x) : x**2 - 2 def df(x) : 2*x # 根 r = math.sqrt(2) # 牛頓迭代法 a , k , tol = 2 , 0 , 1.e-14 err = abs(a-r) print( "> 牛頓迭代法:" ) print( "{:<2} : {:<10e} {:<10e}".format(k,a,err) , sep="" ) while True : b = a - f(a)/df(a) err = abs(b-r) k += 1 # 迭代次數 近似根 誤差,以下 10e 代表以 10 格與科學記號呈現數字 print( "{:<2} : {:<10e} {:<10e}".format(k,b,err) , sep="" ) # 函數絕對值小於 tol 才跳離迭代 if abs(f(b)) < tol : break a = b 數值求根法 :牛頓迭代法 (三) 國立中央大學數學系
  • 4. 4 程式輸出: > 牛頓迭代法: 0 : 2.000000e+00 5.857864e-01 1 : 1.500000e+00 8.578644e-02 2 : 1.416667e+00 2.453104e-03 3 : 1.414216e+00 2.123901e-06 4 : 1.414214e+00 1.594724e-12 5 : 1.414214e+00 0.000000e+00 數值求根法 :牛頓迭代法 (四) 國立中央大學數學系