Download presentation
Presentation is loading. Please wait.
1
Algorithms and Convergence
Sec:1.3 Algorithms and Convergence
2
Sec:1.3 Algorithms and Convergence
An algorithm is a procedure that describes, in an unambiguous manner, a finite sequence of steps to be performed in a specified order. The object of the algorithm is to implement a procedure to solve a problem or approximate a solution to the problem. We use a pseudocode to describe the algorithms. This pseudocode specifies the form of the input to be supplied and the form of the desired output.
3
Sec:1.3 Algorithms and Convergence
Looping techniques counter-controlled x=1:5; vsum = 0; for i=1:5 vsum = vsum + x(i); end vsum conditional execution x=1:5; vsum = 0; for i=1:5 vsum = vsum + x(i); if vsum > 5; break; end vsum condition-controlled x=1:5; vsum = 0; i=1; while i < 3 vsum = vsum + x(i); i = i + 1; end vsum Indentation
4
Sec:1.3 Algorithms and Convergence
π· π΅ π = πβπ π β πβπ π π πβπ π π ββ¦+ βπ π΅+π πβπ π΅ π Calculate: π· π π.π clear; clc n = 9; x=1.5; s=+1; pw = x-1; pn = s*pw; for i = 2:n s = -s; pw=pw*(x-1); term = s*pw/i; pn = pn + term; end pn clear; clc n = 9; x=1.5; pn = 0; for i = 1:n term = (-1)^(i+1)*(x-1)^i/i; pn = pn + term; end pn
5
Sec:1.3 Algorithms and Convergence
Construct an algorithm to determine the minimal value of N required for π· π΅ π = πβπ π β πβπ π π πβπ π π ββ¦+ βπ π΅+π πβπ π΅ π | ππβ‘π.π β π· π΅ (π.π)| < ππ βπ , πΊ π΅ = π.π π β π.π π π π.π π π ββ¦+ βπ π΅+π π.π π΅ π clear; clc n = 13; x=1.5; pn = 0; for i = 1:n term = (-1)^(i+1)*(x-1)^i/i; pn = pn + term; end pn From calculus we know that |π β π π | β€ | π‘πππ π+1 |. if abs(term) < 1e-5; N=i; break; end
6
Sec:1.3 Algorithms and Convergence
Algorithm is stable small changes in the initial data produce correspondingly small changes in the final results. otherwise it is unstable. Some algorithms are stable only for certain choices of initial data, and are called conditionally stable. Example: How small is π
π₯ π₯β22=0 π₯ 1 π₯ 2 π₯ 1 β π₯ 1 (π.ππππ) π₯ π₯β22=0 π₯ 1 π₯ 2 π₯ 2 β π₯ 2 |π
βπ.ππππ| π₯ 1 β π₯ 1 π₯ 2 β π₯ 2 small changes in the initial data produce small changes
7
Sec:1.3 Algorithms and Convergence
Example Rates of Convergence Consider the following two series sequence: {Ξ±n} ο Ξ± π πΆ π πΈ π { πΆ π βπΆ} ο 0 1 2 3 4 5 6 7 then we say that {Ξ±n} converges to Ξ± with rate (order) of convergence O( ( π π ) π ). βbig oh ofβ If a positive constant K exists with |Ξ±n β Ξ±| β€ K 1 π π for large n, πΆ π = π+π π π πΈ π = π+π π π Then we write: Which one is faster? Ξ±n = Ξ± + O( ( 1 π ) π ). Rate of convergence Remark: Comparsion test and Limit comparison test
8
Sec:1.3 Algorithms and Convergence
Example Rates of Convergence Consider the following two series sequence: {Ξ±n} ο Ξ± πΆ π = π+π π π πΈ π = π+π π π { πΆ π βπΆ} ο 0 then we say that {Ξ±n} converges to Ξ± with rate (order) of convergence O( ( π π ) π ). πΆ π = π+π π π β€π ( π π ) π βbig oh ofβ π=π If a positive constant K exists with πΈ π = π+π π π β€π ( π π ) π π=π |Ξ±n β Ξ±| β€ K 1 π π for large n, Then we write: Ξ±n = Ξ± + O( ( 1 π ) π ). Remark: Comparsion test and Limit comparison test
9
Sec:1.3 Algorithms and Convergence
Rates of Convergence Suppose {Ξ²n} is a sequence known to converge to zero, and {Ξ±n} converges to a number Ξ±. If a positive constant K exists with |Ξ±n β Ξ±| β€ K|Ξ²n|, for large n, then we say that {Ξ±n} converges to Ξ± with rate (order) of convergence O(Ξ²n). (This expression is read βbig oh of Ξ²nβ.) Rates of Convergence |Ξ±n β Ξ±| β€ K 1 π π for large n, Two sequences: {Ξ±n} ο Ξ± { π½ π = ( 1 π ) π } ο 0 We are generally interested in the largest value of p with Ξ±n = Ξ± + O( ( 1 π ) π ).
10
Root-finding problem π π₯ = 0
The root-finding problem is a process involves finding a root, or solution, of an equation of the form π π₯ = 0 for a given function π . A root of this equation is also called a zero of the function π . In graph, the root (or zero) of a function is the x-intercept Three numerical methods for root-finding Sec(2.1): The Bisection Method Sec(2.2): Fixed point Iteration root Sec(2.3): The Newton-Raphson Method
11
π π π Newtonβs Method π π₯ =0
THE NEWTON-RAPHSON METHOD is a method for finding successively better approximations to the roots (or zeroes) of a function. Example Algorithm Use the Newton-Raphson method to estimate the root of f (x) = π βπ βπ, employing an initial guess of x1 = 0. To approximate the roots of π π₯ =0 Given initial guess π₯ 1 f (x) = π βπ βπ π β² π =βπ βπ βπ f (0) =π π β² π = βπ π₯ π+1 = π₯ π β π( π₯ π ) πβ²( π₯ π ) π₯ 1 =0 π₯ 2 = π₯ 1 β π( π₯ 1 ) πβ²( π₯ 1 ) π₯ 2 =0β π(0) πβ²(0) π π π =0.5 π₯ 3 =0.5β π(0.5 ) πβ²(0.5 ) = The true value of the root: Thus, the approach rapidly converges on the true root.
12
Newtonβs Method THE NEWTON-RAPHSON METHOD is a method for finding successively better approximations to the roots (or zeroes) of a function. Example clear f exp(-t) - t; df - exp(-t) - 1; x(1) = 0; for i=1:4 x(i+1) = x(i) - f( x(i) )/df( x(i) ); end x' Use the Newton-Raphson method to estimate the root of f (x) = π βπ βπ, employing an initial guess of x1 = 0. π π π
13
π π π (Newton) Newtonβs Method Example Approximate a root of
f (x) = ππππ β π using Newtonβs Method employing an initial guess of ππ = π
π clear f exp(-t) - t; df - exp(-t) - 1; x(1) = 0; for i=1:4 x(i+1) = x(i) - f( x(i) )/df( x(i) ); end x' π π π (Newton) 1 2 3 4 5 6 7 8
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.