Lecture 5 Fixed point iteration Download fixedpoint.m From math.unm.edu/~plushnik/375.

Slides:



Advertisements
Similar presentations
M. Dumbser 1 / 23 Analisi Numerica Università degli Studi di Trento Dipartimento dIngegneria Civile ed Ambientale Dr.-Ing. Michael Dumbser Lecture on Numerical.
Advertisements

Mathematics Roots, Differentiation and Integration Prof. Muhammad Saeed.
Part 2 Chapter 6 Roots: Open Methods
Lecture 5.
Numerical Computation Lecture 4: Root Finding Methods - II United International College.
Chapter 6: Roots: Open Methods
Lecture 5 Newton-Raphson Method
Solution of Nonlinear Equation (b)
Fixed point iterations and solution of non-linear functions
Part 2 Chapter 6 Roots: Open Methods
MATLAB Optimization Greg Reese, Ph.D Research Computing Support Group Miami University.
Numerical Solution of Nonlinear Equations
Line Search.
Polynomial Approximation PSCI 702 October 05, 2005.
Suggested problems from text (6 th edition) Chapter 3.1 p85 Problems 1, 4, 9, 10 Computer problems 1, 2, 4, 7 Chapter 3.2 p101 Problems 4, 15, 17, 19 Computer.
CSE 330: Numerical Methods
Lecture 26: Numerical Integration Trapezoid rule Simpson's rule Simpson's 3/8 rule Boole’s rule Newton-Cotes Formulas.
Lecture 14: Newton’s method for system of two nonlinear equations Function newton2d01 Set initial (x,y) point, maximum number of iterations, and convergence.
3-2 What are relational operators and logical values? How to use the input and disp functions. Learn to use if, if-else and else-if conditional statements.
Open Methods.
Chapter 4 Roots of Equations
Chapter 6 Open Methods.
ENGG 1801 Engineering Computing MATLAB Lecture 7: Tutorial Weeks Solution of nonlinear algebraic equations (II)
Nonlinear Algebraic Systems 1.Iterative solution methods 2.Fixed-point iteration 3.Newton-Raphson method 4.Secant method 5.Matlab tutorial 6.Matlab exercise.
Fin500J: Mathematical Foundations in Finance Topic 3: Numerical Methods for Solving Non-linear Equations Philip H. Dybvig Reference: Numerical Methods.
Secant Method Another Recursive Method. Secant Method The secant method is a recursive method used to find the solution to an equation like Newton’s Method.
MATH 175: NUMERICAL ANALYSIS II Lecturer: Jomar Fajardo Rabajante IMSP, UPLB 2 nd Semester AY
Roots of Equations Chapter 3. Roots of Equations Also called “zeroes” of the equation –A value x such that f(x) = 0 Extremely important in applications.
MATH 685/ CSI 700/ OR 682 Lecture Notes Lecture 8. Nonlinear equations.
Lecture 28: Comparison of different numerical integrators 1.Adaptive Simpson’s and Trapezoid Rules 2. Romberg Integration 3. Adaptive Gaussian Quadrature.
CMPSC 200 Spring 2013 Lecture 38 November 18 or 20, 2013 (depending on section)
Root Finding The solution of nonlinear equations and systems Vageli Coutsias, UNM, Fall ‘02.
Chapter 6 Finding the Roots of Equations
Neural Networks1 Introduction to NETLAB NETLAB is a Matlab toolbox for experimenting with neural networks Available from:
Lecture 3 Bisection method Download bisection02.m And ftest2.m From math.unm.edu/~plushnik/375.
Quadrature rules 1Michael Sokolov / Numerical Methods for Chemical Engineers / Numerical Quadrature Michael Sokolov ETH Zurich, Institut für Chemie- und.
Numerical Methods.
Solution of Nonlinear Functions
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Roots of Equations ~ Bracketing Methods Chapter 5.
Newton’s Method, Root Finding with MATLAB and Excel
4 Numerical Methods Root Finding Secant Method Modified Secant
linear  2.3 Newton’s Method ( Newton-Raphson Method ) 1/12 Chapter 2 Solutions of Equations in One Variable – Newton’s Method Idea: Linearize a nonlinear.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
Numerical Methods Solution of Equation.
More Functions in MATLAB. Functions that operate on other functions A function F() can take another function G() as an argument by using a notation:
Finding zeros (also called roots) of a function Overview: Define the problem Methods of solution Graphical Newton’s Bisection Secant.
4 Numerical Methods Root Finding Secant Method Modified Secant
Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.
Part 3 Chapter 12 Iterative Methods
SOLVING NONLINEAR EQUATIONS. SECANT METHOD MATH-415 Numerical Analysis 1.
Root Finding UC Berkeley Fall 2004, E77 Copyright 2005, Andy Packard. This work is licensed under the Creative.
Finding zeros (also called roots) of a function Overview: Define the problem Methods of solution Graphical Newton’s Bisection Secant.
MA2213 Lecture 9 Nonlinear Systems. Midterm Test Results.
6/13/ Secant Method Computer Engineering Majors Authors: Autar Kaw, Jai Paul
CSE 330: Numerical Methods. What is true error? True error is the difference between the true value (also called the exact value) and the approximate.
CSE 330: Numerical Methods. Introduction The bisection and false position method require bracketing of the root by two guesses Such methods are called.
4 Numerical Methods Root Finding Secant Method Modified Secant
Solution of Nonlinear Equations (Root finding Problems
~ Roots of Equations ~ Bracketing Methods Chapter 5
Read Chapters 5 and 6 of the textbook
Part 2 Chapter 6 Roots: Open Methods
Secant Method – Derivation
ENGG 1801 Engineering Computing
MATH 2140 Numerical Methods
MATH 175: Numerical Analysis II
SOLUTION OF NONLINEAR EQUATIONS
Programming assignment #1 Solving an elliptic PDE using finite differences Numerical Methods for PDEs Spring 2007 Jim E. Jones.
Part 2 Chapter 6 Roots: Open Methods
Iteration – While Loops
Presentation transcript:

Lecture 5 Fixed point iteration Download fixedpoint.m From math.unm.edu/~plushnik/375

%fixedpoint.m - solution of nonlinear equation by fixed point iterations function [x,n, xn] = fixedpoint(f, x0, tol, nmax) % find the root of equation x=f(x) by fixed point method; % input: % f - inline function % x0 - initial guess % tol - exit condition f(x) < tol % nmax - maximum number of iterations % output: % x - the approximation for the root % n - number of iterations % xn - vector of apporximations x(iter) % compute function at initial guesses f0 = f(x0); n = 0; % begin iterations while ((abs(f0-x0) > tol) && (n < nmax)) x0 = f0; f0 = f(x0); disp(['Error: f0-x0=',num2str(f0-x0)]); if f0 == x0 % x0 is a root, done break; end n = n+1; xn(n) = x0; end if n==nmax disp('warning: maximum iterations reached without conversion'); end x=x0; disp(['Number of iterations: n = ',num2str(n)]); end

>> g1=inline('1-x^3'); >> g2=inline('(1-x)^(1/3)'); >> g3=inline('(1+2*x^3)/(1+3*x^2)'); Enter inline functions:

>>fixedpoint(g1,0.5,10^(-8),10); Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0=-1 Error: f0-x0=1 Error: f0-x0=-1 Error: f0-x0=1 warning: maximum iterations reached without conversion Number of iterations: n = 10

>> fixedpoint(g2,0.5,10^(-8),100); Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0= Error: f0-x0=9.6501e-005 Error: f0-x0= e-005 Error: f0-x0=4.9467e-005 Error: f0-x0= e-005 Error: f0-x0=2.5357e-005 Error: f0-x0= e-005 Error: f0-x0=1.2998e-005 Error: f0-x0= e-006 Error: f0-x0=6.663e-006 Error: f0-x0= e-006 Error: f0-x0=3.4155e-006 Error: f0-x0= e-006 Error: f0-x0=1.7508e-006 Error: f0-x0= e-006 Error: f0-x0=8.9748e-007 Error: f0-x0= e-007 Error: f0-x0=4.6006e-007 Error: f0-x0= e-007 Error: f0-x0=2.3583e-007 Error: f0-x0= e-007 Error: f0-x0=1.2089e-007 Error: f0-x0= e-008 Error: f0-x0=6.1968e-008 Error: f0-x0= e-008 Error: f0-x0=3.1765e-008 Error: f0-x0= e-008 Error: f0-x0=1.6283e-008 Error: f0-x0= e-008 Error: f0-x0=8.3468e-009 Number of iterations: n = 52

>> fixedpoint(g3,0.5,10^(-8),100); Error: f0-x0= Error: f0-x0= Error: f0-x0= e-007 Error: f0-x0= e-013 Number of iterations: n = 4 >>

Secant method Download secant02.m And ftest2.m From math.unm.edu/~plushnik/375

%Secant method to find roots for function ftest2 x0=0.1; x1=2.0;%starting points abserr=10^(-14); %stop criterion - desired absolute error istep=0; xn1=x0; %set initial value of x to x0 xn=x1; %main loop to find root disp('Iterations by Secant Method'); while abs(ftest2(xn))>abserr istep=istep+1; fn=ftest2(xn); fn1=ftest2(xn1); disp(['f(x)=',num2str(fn),' xn=',num2str(xn,15)]);%display value of function f(x) xtmp=xn-(xn-xn1)*fn/(fn-fn1); xn1=xn; xn=xtmp; end f=ftest2(xn); disp(['f(x)=',num2str(fn),' xn=',num2str(xn,15)]);%display value of function f(x) disp(['number of steps for Secant algorithm=',num2str(istep)]);

%test function is defined at fourth line; %derivative of function is defined at firth line function [f,fderivative]=ftest2(x) f=exp(2*x)+x-3; fderivative=2*exp(2*x)+1;

>> secant02 Iterations by Secant Method f(x)= xn=2 f(x)= xn= f(x)= xn= f(x)= xn= f(x)= xn= f(x)= xn= f(x)=7.5808e-005 xn= f(x)= e-008 xn= f(x)= e-013 xn= f(x)= e-013 xn= number of steps for Secant algorithm=9 >>

Inclass3 Modify secant02.m and ftest2.m to find root of e^(-x)-x=0 by secant method starting at x=0.2 and x=1.5

>> secant02 Iterations by Secant Method f(x)= xn=1.5 f(x)= xn= f(x)= xn= f(x)= xn= f(x)= e-007 xn= f(x)=2.9781e-012 xn= f(x)=2.9781e-012 xn= number of steps for Secant algorithm=6 Answer to inclass3

Matlab function: fzero X = FZERO(FUN,X0), X0 a scalar: Attempts to find a zero of the function FUN near X0. FUN is a function handle. The value X returned by FZERO is near a point where FUN changes sign (if FUN is continuous), or NaN, if the srootfinding search fails. X = FZERO(FUN,X0), X0 a 2-vector. Assumes that FUN(X0(1)) and FUN(X0(2)) differ in sign, insuring a root. X = FZERO(FUN,X0,OPTIONS). Solves the equation with default optimization parameters replaced by values in the string OPTIONS, an argument created with the OPTIMSET function.

>> options = optimset('disp', 'iter', 'tolx', 1.e-15); >> 2],options) Func-count x f(x) Procedure initial interpolation interpolation interpolation interpolation e-005 interpolation e-008 interpolation e-014 interpolation interpolation Zero found in the interval [0.1, 2] ans = >> Example of fzero use

Inclass4 Modify ftest2.m to find root of e^(-x)-x=0 by Brent’s method starting at x=0.2 and x=1.5

>> 1.5],options) Func-count x f(x) Procedure initial interpolation interpolation e-006 interpolation e-010 interpolation e-016 interpolation e-016 interpolation Zero found in the interval [0.2, 1.5] ans = Answer to inclass4