Download presentation
Presentation is loading. Please wait.
Published byRodney Wilcox Modified over 9 years ago
1
數值方法 2008, Applied Mathematics NDHU1 An iterative approach for root finding Newton method Lecture 3II Root Finding
2
數值方法 2008, Applied Mathematics NDHU2 Problem statement Find x such that f(x)=0 for a given f f denotes an arbitrary single-variable function Root finding
3
數值方法 2008, Applied Mathematics NDHU3 >> x=linspace(-1,3); >> plot(x,2.^x.^2-10*x+1)
4
數值方法 2008, Applied Mathematics NDHU4 Root finding Input: an expression Plot given function Find a root
5
數值方法 2008, Applied Mathematics NDHU5 Tangent line x xnxn y=f(x) y n =f(x n ) x n+1
6
Taylor series 數值方法 2008, Applied Mathematics NDHU6
7
7 An iterative approach Start at some guess Refine current guess by Find a tangent line that passes (x n,f(x n )) Set x n to a point at intersection of the tangent line to horizontal axis
8
數值方法 2008, Applied Mathematics NDHU8 Updating rule
9
數值方法 2008, Applied Mathematics NDHU9 Newton method An Iterative approach Random guess Refine current guess by an updating rule If a halting condition holds, go to step 2 otherwise exit
10
數值方法 2008, Applied Mathematics NDHU10 An iterative approach n=0 ; x n n=0 ; Set x n x n+1 Determine x n+1 Increase n by one Halting condition T F
11
數值方法 2008, Applied Mathematics NDHU11 An iterative approach x randomly Set x randomly an updating rule Apply an updating rule x to refine x ~( halting condition) exit
12
數值方法 2008, Applied Mathematics NDHU12 Halting condition Let x denote the current guess The absolute value of f(x) is expected as close as possible to zero Halting Condition abs(f(x)) < epslon epslon denotes a predefined small positive number
13
數值方法 2008, Applied Mathematics NDHU13 Initialization Random initialization A guess by the user
14
數值方法 2008, Applied Mathematics NDHU14 An iterative approach x = rand*2-1; s=sym(ss); ep=10^-6 f=inline(s); s1=diff(s); f1=inline(s1) x=x-f(x)/f1(x); fprintf('%f\n',x) ~( abs(f(x)) < ep) exit input an expression, ss
15
數值方法 2008, Applied Mathematics NDHU15 Demo_newton source codesource code demo_newton fstr=input('input a function:','s'); x_ini=input('guess its zero:'); x_zero=newton(fstr,x_ini); newton.m
16
數值方法 2008, Applied Mathematics NDHU16 Main Program
17
數值方法 2008, Applied Mathematics NDHU17 Newton method
18
數值方法 2008, Applied Mathematics NDHU18 >> demo_newton input a function:cos(x) guess its zero:2 iter=1 x=1.542342 fx=0.028450 iter=2 x=1.570804 fx=-0.000008 iter=3 x=1.570796 fx=0.000000 >>
19
數值方法 2008, Applied Mathematics NDHU19 Example demo_newton input a function:2.^x.^2-10*x+1 guess its zero:1.5
20
數值方法 2008, Applied Mathematics NDHU20 Example >> demo_newton input a function:2.^x.^2-10*x+1 guess its zero:0.5
21
Second order expansion 數值方法 2008, Applied Mathematics NDHU21
22
Second order method Update rule 數值方法 2008, Applied Mathematics NDHU22
23
數值方法 2008, Applied Mathematics NDHU23 An iterative approach x = rand*2-1; s=sym(ss); ep=10^-6 f=inline(s); s1=diff(s); f1=inline(s1) s2=diff(s1); f2=inline(s2) a=f2(x)/2;b=-f2(x)+f1(x);c=f(x)-x*f1(x)+f2(x)*x^2/2;x=… fprintf('%f\n',x) ~( abs(f(x)) < ep) exit input an expression, ss
24
數值方法 2008, Applied Mathematics NDHU24 Unconstrained Optimization Problem statement Given a differentiable function, y=g(x), unconstrained optimization aims to find the minimum of g(x) Let x denote a minimum and
25
數值方法 2008, Applied Mathematics NDHU25 Optimization by Newton method Use symbolic differentiation to find the first derivative of a given function Apply the Newton method to find zeros of the first derivative
26
數值方法 2008, Applied Mathematics NDHU26 An iterative approach x = rand*2-1; s=sym(ss); ep=10^-6 g=inline(s); s1=diff(s); f=inline(s1); s2=diff(s1); f1=inline(s2) x=x-f(x)/f1(x); fprintf('%f gx=%f\n',x, g(x)) ~( abs(f(x)) < ep) exit input an expression, ss
27
數值方法 2008, Applied Mathematics NDHU27 First derivative ss=input('input a function:','s'); s=sym(ss); f=inline(s); s1=diff(s); f1=inline(s1); x=linspace(-5,5); plot(x,f(x));hold on; plot(x,f1(x));
28
數值方法 2008, Applied Mathematics NDHU28 >> x=linspace(-2*pi,2*pi); >> plot(x,(x-tanh(2*x+10)).^2)
29
數值方法 2008, Applied Mathematics NDHU29 >> demo_min input a function:(x-tanh(2*x+10)).^2 guess its minimum:4 Local minimum
30
數值方法 2008, Applied Mathematics NDHU30 >> demo_min input a function:(x-tanh(2*x+10)).^2 guess its minimum:-4 Local Minimum
31
數值方法 2008, Applied Mathematics NDHU31 Global minimum
32
數值方法 2008, Applied Mathematics NDHU32 >> demo_min input a function:0.2*x.^3-3*x+cos(x) guess its minimum:2
33
數值方法 2008, Applied Mathematics NDHU33 Exercise ex3II.pdf
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.