CS 221 Lecture 9. Tuesday, 1 November 2011

Similar documents
SOLVING EQUATIONS OF ONE VARIABLE

Solution of Algebric & Transcendental Equations

Nonlinearity Root-finding Bisection Fixed Point Iteration Newton s Method Secant Method Conclusion. Nonlinear Systems

Numerical Methods Lecture 3

THE SECANT METHOD. q(x) = a 0 + a 1 x. with

Numerical Analysis Fall. Roots: Open Methods

Root Finding Convergence Analysis

Numerical Methods. Roots of Equations

INTRODUCTION, FOUNDATIONS

Computer Applications in Engineering and Construction Programming Assignment #4 Chemical equilibrium using root-finding techniques

Queens College, CUNY, Department of Computer Science Numerical Methods CSCI 361 / 761 Spring 2018 Instructor: Dr. Sateesh Mane.

Nonlinearity Root-finding Bisection Fixed Point Iteration Newton s Method Secant Method Conclusion. Nonlinear Systems

Numerical Solution of f(x) = 0

PLC Papers. Created For:

converges to a root, it may not always be the root you have in mind.

Nonlinear Equations and Continuous Optimization

Lecture 7. Root finding I. 1 Introduction. 2 Graphical solution

MATH 3795 Lecture 12. Numerical Solution of Nonlinear Equations.

Numerical Methods. Root Finding

NON-LINEAR ALGEBRAIC EQUATIONS Lec. 5.1: Nonlinear Equation in Single Variable

Zeroes of Transcendental and Polynomial Equations. Bisection method, Regula-falsi method and Newton-Raphson method

Homework 2. Matthew Jin. April 10, 2014

MAT01A1: Functions and Mathematical Models

Finding the Roots of f(x) = 0. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Finding the Roots of f(x) = 0

TWO METHODS FOR OF EQUATIONS

p 1 p 0 (p 1, f(p 1 )) (p 0, f(p 0 )) The geometric construction of p 2 for the se- cant method.

MATH 350: Introduction to Computational Mathematics

Scientific Computing. Roots of Equations

Polynomial Functions and Their Graphs

MATH 350: Introduction to Computational Mathematics

CHAPTER-II ROOTS OF EQUATIONS

University of Delaware Department of Mathematical Sciences Math 353 Engineering Mathematics III 06S C. Bacuta

2D Plotting with Matlab

Lecture 44. Better and successive approximations x2, x3,, xn to the root are obtained from

CHAPTER 4 ROOTS OF EQUATIONS

MA 113 Calculus I Fall 2015 Exam 3 Tuesday, 17 November Multiple Choice Answers. Question

Day 6: 6.4 Solving Polynomial Equations Warm Up: Factor. 1. x 2-2x x 2-9x x 2 + 6x + 5

Goals for This Lecture:

1. Method 1: bisection. The bisection methods starts from two points a 0 and b 0 such that

Design and Optimization of Energy Systems Prof. C. Balaji Department of Mechanical Engineering Indian Institute of Technology, Madras

Root finding. Eugeniy E. Mikhailov. Lecture 06. The College of William & Mary. Eugeniy Mikhailov (W&M) Practical Computing Lecture 06 1 / 10

Algebra Revision Guide

Regent College Maths Department. Further Pure 1 Numerical Solutions of Equations

CE 205 Numerical Methods. Some of the analysis methods you have used so far.. Algebra Calculus Differential Equations etc.

PART I Lecture Notes on Numerical Solution of Root Finding Problems MATH 435

INTRODUCTION TO NUMERICAL ANALYSIS

COMPUTING AND DATA ANALYSIS WITH EXCEL. Numerical Methods of Solving Equations

Root finding. Root finding problem. Root finding problem. Root finding problem. Notes. Eugeniy E. Mikhailov. Lecture 05. Notes

Section 6: Summary Section 7

CS1210 Lecture 23 March 8, 2019

COMPUTER SCIENCE TRIPOS

Computational Methods for Engineers Programming in Engineering Problem Solving

Analysis Methods in Atmospheric and Oceanic Science

Finding Roots of Equations

An Invitation to Mathematics Prof. Sankaran Vishwanath Institute of Mathematical Sciences, Chennai. Unit I Polynomials Lecture 1A Introduction

Solution of Nonlinear Equations: Graphical and Incremental Sea

Zeros of functions with Matlab: Bisection method and fixed point iteration

Analysis Methods in Atmospheric and Oceanic Science

Nonlinear Equations. Your nonlinearity confuses me.

Root finding. Eugeniy E. Mikhailov. Lecture 05. The College of William & Mary. Eugeniy Mikhailov (W&M) Practical Computing Lecture 05 1 / 10

Lab 2: Static Response, Cantilevered Beam

CHAPTER EIGHT: SOLVING QUADRATIC EQUATIONS Review April 9 Test April 17 The most important equations at this level of mathematics are quadratic

SOLUTION OF ALGEBRAIC AND TRANSCENDENTAL EQUATIONS BISECTION METHOD

Analytic Trigonometry. Copyright Cengage Learning. All rights reserved.

Simple Iteration, cont d

Wednesday, 10 September 2008

BSM510 Numerical Analysis

Outline. Wednesday, 10 September Schedule. Welcome to MA211. MA211 : Calculus, Part 1 Lecture 2: Sets and Functions

Lecture 8. Root finding II

More on infinite series Antiderivatives and area

Mathematics Textbook Correlation to the 2016 Algebra I Standards of Learning and Curriculum Framework

Exact and Approximate Numbers:

Introduction Propositional Logic

COURSE: Essentials of Calculus GRADE: 12 PA ACADEMIC STANDARDS FOR MATHEMATICS:

Numerical Methods Dr. Sanjeev Kumar Department of Mathematics Indian Institute of Technology Roorkee Lecture No 7 Regula Falsi and Secant Methods

Pre-Algebra Lesson Plans

3.1 Introduction. Solve non-linear real equation f(x) = 0 for real root or zero x. E.g. x x 1.5 =0, tan x x =0.

CME Project, Algebra Correlated to: Michigan High School Content Expectations, Algebra 1

Section Summary. Sequences. Recurrence Relations. Summations. Examples: Geometric Progression, Arithmetic Progression. Example: Fibonacci Sequence

1.2. Indices. Introduction. Prerequisites. Learning Outcomes

PLC Papers. Created For:

Numerical Methods I Solving Nonlinear Equations

Morpheus: Neo, sooner or later you re going to realize, just as I did, that there s a difference between knowing the path, and walking the path.

Examples of metric spaces. Uniform Convergence

Lecture 20 - Plotting and Nonlinear Equations

Solutions of Equations in One Variable. Newton s Method

Honors Advanced Mathematics November 4, /2.6 summary and extra problems page 1 Recap: complex numbers

What if the characteristic equation has complex roots?

Math Lecture 4 Limit Laws

Extended Introduction to Computer Science CS1001.py. Lecture 8 part A: Finding Zeroes of Real Functions: Newton Raphson Iteration

CS173 Lecture B, November 3, 2015

ICS141: Discrete Mathematics for Computer Science I

arb where a A, b B and we say a is related to b. Howdowewritea is not related to b? 2Rw 1Ro A B = {(a, b) a A, b B}

CS 323: Numerical Analysis and Computing

15 Nonlinear Equations and Zero-Finders

Nonlinear Equations. Not guaranteed to have any real solutions, but generally do for astrophysical problems.

LIMITS AND DERIVATIVES

First Derivative Test

I. Numerical Computing

Transcription:

CS 221 Lecture 9 Tuesday, 1 November 2011 Some slides in this lecture are from the publisher s slides for Engineering Computation: An Introduction Using MATLAB and Excel 2009 McGraw-Hill

Today s Agenda 1. Announcements 2. Passing functions as parameters to other functions 3. Solving equations 4. Numerical Root-finding methods (Text: Ch. 6) a. b. c. Bisection Newton s Method MATLAB s built-in methods: fzero() and roots() 5. Lab Quiz What to expect

1. Announcements Problem Set 3 is out Due Monday 7 November Lab Quiz 2 this Thursday All-MATLAB Example problems later & posted on Web page

2. Functions As Parameters Sometimes it s useful to pass a function as a parameter to another function You want to use a function without knowing exactly what it is This is useful for: Plotting see fplot() Numerical (not symbolic) manipulations Integration: finding the area under the curve of f(x) Finding roots of equations f(x) = 0

Two Ways to Pass Functions As Parameters 1. Pass the name of the function as a string (in quotes) Examples: fplot( cos, [-pi, pi]) g( f,1,2) 2. Pass the name of the function preceded by @ Syntax: @funcname Semantics: @cos is a function handle a pointer to the cosine function Examples fplot(@cos, [-pi, pi]) g(@f,1,2)

Function Handles have many uses. You can assign a function handle to a variable func = @cos; Now func(x) returns the same thing as cos(x) Pass a parameter to a user-defined function Example: bisect() coming soon Use of function handles is required function handle is a real type in MATLAB like double or char

3. Solving Equations We consider algebraic equations of the form: f(x) = 0 Single unknown: x Linear: multiply and add constants: f(x) = 3x + 4.0321; Polynomials: Sums of (non-negative) integer powers of x, multiplied by real constants f(x) = 3x 5 + 2.5x 3 + x 2 + 100x 10.5 General Nonlinear Non-integer powers of x, transcendentals, logs, etc: f(x) = x 3/2 + log x + x sin x

Solution Approaches Analytical (algebra) What you ve been doing since high school Fine for linear and some polynomial equations Often impractical in real world situations Graphical Plot the function see where it crosses the x-axis Numerical

4. Numerical Root-Finding Methods

Finding Roots Problem: given f(x), find the roots of f I.e., value(s) of x for which f(x) = 0 Approaches: Solve analytically Quadratic equations, some polynomials,... Solve graphically Low precision Solve numerically When the other methods aren t adequate All you need is the function itself That is: you give it x, it gives back f(x)

Graphical Method Graph the function in the region of interest See where it crosses the y-axis

Finding Roots Numerically: General Approach <Given function f plus starting_info> <initialize> estimate = <set based on starting_info> while estimated_error > error_spec old_estimate = estimate; estimate = <refine estimate, using f>; estimated_error = % update the error estimate (old_estimate estimate)/estimate; end

The Bisection Method Principle: If the signs of f(m) and f(n) differ, there exists an odd number of roots (at least 1) between m and n...or there is a discontinuity between m and n Method: Find m and n such that f(m) x f(n) < 0 Compute r = (m+n)/2 and f(r) If f(r) has the same sign as f(m), replace m by r else [f(r) has same sign as f(n)] replace n by r

Bisection Method: Error estimation We know there is a root between m and n Estimate = (f(m) + f(n))/2 Root must be within (f(m) f(n))/2 of this estimate! The interval [m,n] shrinks with every iteration!

Bisection Method: Error estimation We know there is a root between m and n Estimate = (f(m) + f(n))/2 Root must be within m n /2 of this estimate! The interval [m,n] shrinks with every iteration

Bisection Method: Error estimation We know there is a root between m and n Estimate = (f(m) + f(n))/2 Root must be within m n /2 of this estimate! The interval [m,n] shrinks with every iteration

Bisection Method Example - Polynomial

Bisection Method Example - Polynomial

Bisection Method Example - Polynomial

Bisection Method Example - Polynomial

Bisection Method Example - Polynomial

Bisection Method Example - Polynomial

Bisection Method Summary A bracketing method Guaranteed to converge May take a long time to converge if root is near one of the bounds Provides guaranteed upper bound on the absolute (not relative!) error

Open Root-finding Methods Bisection method requires two input x-values for which the sign of f(x) differs They thus bracket the root These are called closed methods Open methods do not require knowledge of where the root lies Some only need one initial guess BUT they may not converge

For x = 10: This is the new value of x

Newton-Raphson Method Advantages: Fast convergence Error on i+1 st iteration proportional to square of error on i th iteration Number of correct decimal places roughly doubles each iteration (assuming convergence!) Disadvantages: Derivative must be known No general convergence criterion Implementation suggestions: Include a limit on number of iterations Check for f (x) = 0 during computation

MATLAB s Built-in Root-finding Tools fzero() root = fzero(@func,[low,high]); root = fzero(@func,guess); Uses a combination of methods (See the help under finding roots ) roots() Solves for all roots of a polynomial

>> A = [3, -15, -20, 50]; >> roots(a) ans = 5.6577-2.0764 1.4187

>> B = [3, -5, -20, 50]; >> roots(b) ans = -2.8120 2.2393 + 0.9553i 2.2393-0.9553i

5. Lab Quiz What to Expect One problem will involve correcting a script it will likely involve fprintf(), logic, iteration One problem will involve writing a function from scratch it will involve computing with arrays it will involve iteration (while- and/or for-loops)

Example Here s a function that is supposed to return a vector whose elements are the differences between adjacent elements in the input vector. Correct it: function x = vecdiff(invec) len = size(invec); for i=1:len x(i) = invec(i) invec(i+1); end end

Example, cont. For input: [ 0, 3, -20, 8, 10, 7 ] Correct return value is: [ 3, -23, 28, 2, -3 ] function x = vecdiff(invec) len = size(invec); for i=1:len x(i) = invec(i) invec(i+1); end end

Example Write a function that takes a 2-dimensional matrix and returns the maximum difference between any two elements