MAE 107 Homework 7 Solutions

Similar documents
Root Finding: Close Methods. Bisection and False Position Dr. Marco A. Arocha Aug, 2014

Bisection and False Position Dr. Marco A. Arocha Aug, 2014

Figure 1: Graph of y = x cos(x)

Midterm Review. Igor Yanovsky (Math 151A TA)

Homework #4 Solutions

Chapter 3: Root Finding. September 26, 2005

Determining the Roots of Non-Linear Equations Part I

x x2 2 + x3 3 x4 3. Use the divided-difference method to find a polynomial of least degree that fits the values shown: (b)

Justify all your answers and write down all important steps. Unsupported answers will be disregarded.

Hence a root lies between 1 and 2. Since f a is negative and f(x 0 ) is positive The root lies between a and x 0 i.e. 1 and 1.

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

MAE 107 Homework 8 Solutions

Math 471. Numerical methods Root-finding algorithms for nonlinear equations

Homework 2 - Solutions MA/CS 375, Fall 2005

GAMS. Loops and Conditional Statements. x 2, x < 0. write a GAMS model that calculates the value of f(x) for the following set of x values:

Homework and Computer Problems for Math*2130 (W17).

Outline. Math Numerical Analysis. Intermediate Value Theorem. Lecture Notes Zeros and Roots. Joseph M. Mahaffy,

Math Numerical Analysis

Root Finding Convergence Analysis

Halley s Method: A Cubically Converging. Method of Root Approximation

Practical Numerical Analysis: Sheet 3 Solutions

If you need the source code from the sample solutions, copy and paste from the PDF should work. If you re having trouble, send me an .

Numerical Methods 5633

STOP, a i+ 1 is the desired root. )f(a i) > 0. Else If f(a i+ 1. Set a i+1 = a i+ 1 and b i+1 = b Else Set a i+1 = a i and b i+1 = a i+ 1

MATH 3795 Lecture 12. Numerical Solution of Nonlinear Equations.

Math Numerical Analysis Mid-Term Test Solutions

Numerical Methods Lecture 3

1. Write a program based on computing divided differences one diagonal at a time as shown below: f x 1,x 2

Today s class. Numerical differentiation Roots of equation Bracketing methods. Numerical Methods, Fall 2011 Lecture 4. Prof. Jinbo Bi CSE, UConn

Solution of Algebric & Transcendental Equations

Solving Non-Linear Equations (Root Finding)

Unit 2: Solving Scalar Equations. Notes prepared by: Amos Ron, Yunpeng Li, Mark Cowlishaw, Steve Wright Instructor: Steve Wright

Numerical methods. Examples with solution

4. We accept without proofs that the following functions are differentiable: (e x ) = e x, sin x = cos x, cos x = sin x, log (x) = 1 sin x

Optimization and Calculus

5. Hand in the entire exam booklet and your computer score sheet.

Homework for Section 1.4, Continuity and One sided Limits. Study 1.4, # 1 21, 27, 31, 37 41, 45 53, 61, 69, 87, 91, 93. Class Notes: Prof. G.

Some MATLAB Programs and Functions. Bisection Method

Continuity. To handle complicated functions, particularly those for which we have a reasonable formula or formulas, we need a more precise definition.

CS 323: Numerical Analysis and Computing

Numerical Solution of f(x) = 0

SOLVING EQUATIONS OF ONE VARIABLE

Lesson 59 Rolle s Theorem and the Mean Value Theorem

Mark Scheme (Results) Summer 2010

Intro to Scientific Computing: How long does it take to find a needle in a haystack?

Chapter 2: Functions, Limits and Continuity

Chapter 8: Taylor s theorem and L Hospital s rule

2.2 The Limit of a Function

AMSC/CMSC 466 Problem set 3

Math 552 Scientific Computing II Spring SOLUTIONS: Homework Set 1

* is a row matrix * An mxn matrix is a square matrix if and only if m=n * A= is a diagonal matrix if = 0 i

Computing Integrals. Lectures INF2320 p. 1/48

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

CHAPTER-II ROOTS OF EQUATIONS

Linearization and Extreme Values of Functions

COURSE Numerical integration of functions (continuation) 3.3. The Romberg s iterative generation method

x 2 x n r n J(x + t(x x ))(x x )dt. For warming-up we start with methods for solving a single equation of one variable.

A Review of Bracketing Methods for Finding Zeros of Nonlinear Functions

Chapter 8 Gauss Elimination. Gab-Byung Chae

Jim Lambers MAT 460/560 Fall Semester Practice Final Exam

Introduction to PDEs and Numerical Methods Lecture 7. Solving linear systems

Mean Value Theorem. MATH 161 Calculus I. J. Robert Buchanan. Summer Department of Mathematics

Taylor and Maclaurin Series. Approximating functions using Polynomials.

Motivation: We have already seen an example of a system of nonlinear equations when we studied Gaussian integration (p.8 of integration notes)

MATH 20B MIDTERM #2 REVIEW

Math-3315 & CSE-3365, exam 2 answer sheet

Intermediate Value Theorem

An Overly Simplified and Brief Review of Differential Equation Solution Methods. 1. Some Common Exact Solution Methods for Differential Equations

Homework 2. Matthew Jin. April 10, 2014

Mean Value Theorem. MATH 161 Calculus I. J. Robert Buchanan. Summer Department of Mathematics

Taylor and Maclaurin Series. Approximating functions using Polynomials.

Qualifying Examination

Chapter 2 Solutions of Equations of One Variable

Homework 5 - Solutions

Scientific Computing: An Introductory Survey

Announcements. Topics: Homework:

SOLUTIONS to Problems for Review Chapter 15 McCallum, Hughes, Gleason, et al. ISBN by Vladimir A. Dobrushkin

Examination paper for TMA4215 Numerical Mathematics

Consider the following example of a linear system:

MA 8019: Numerical Analysis I Solution of Nonlinear Equations

Who am I? Math 1080: Numerical Linear Algebra. Books. Format

ME 535 Project Report Numerical Computation of Plastic Zone Shapes in Fracture Mechanics. V.V.H. Aditya ( ) Rishi Pahuja ( ) June 9, 2014

CS 257: Numerical Methods

Announcements. Topics: Homework: - sections , 6.1 (extreme values) * Read these sections and study solved examples in your textbook!

AIMS Exercise Set # 1

Chapter 1: Limits and Continuity

MAT137 Calculus! Lecture 9

SPECIMEN EXAMINATION 2014/2015 ADEDEX424. Access to Science - Mathematics 1. Dr. Anthony Cronin Dr. Anthony Brown. Time Allowed: 3 hours

Engineering Computation

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

Math Homework 1. The homework consists mostly of a selection of problems from the suggested books. 1 ± i ) 2 = 1, 2.

MATH 552 Spectral Methods Spring Homework Set 5 - SOLUTIONS

R x n. 2 R We simplify this algebraically, obtaining 2x n x n 1 x n x n

Math 261 Calculus I. Test 1 Study Guide. Name. Decide whether the limit exists. If it exists, find its value. 1) lim x 1. f(x) 2) lim x -1/2 f(x)

Section 3.7. Rolle s Theorem and the Mean Value Theorem

Formulas to remember

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

Chapter 6. Additional Topics in Trigonometry. 6.6 Vectors. Copyright 2014, 2010, 2007 Pearson Education, Inc.

Scilab. Prof. S. A. Katre Dept. of Mathematics, University of Pune

5 Finding roots of equations

Transcription:

MAE 107 Homework 7 Solutions 1. Tridiagonal system for u xx (x) + u(x) = 1 + sin(πx/4), for x [0, ], where u(0) =, u() = 4, with step size h = 1/. The total number of segments are: n = 0 1/ =. The nodes will be x 0 through x, with x 0 = 0, x =, and x k+1 x k = 1/. Use difference approximation for u xx (x) at each x k, k = 1,,, 4, 5: The differential equation becomes D h (x k) = u(x k1) u(x k ) + u(x k+1 ) h u(x k1) u(x k ) + u(x k+1 ) h + u(x k ) = 1 + sin( πx k for k = 1,,, 4, 5. Substituting in u(0) = u(x 0 ) =, u() = u(x ) = 4), we get u(x 1) + u(x ) h + u(x 1 ) = 1 + sin( πx 1 u(x 1) u(x ) + u(x ) h + u(x ) = 1 + sin( πx u(x ) u(x ) + u(x h + u(x ) = 1 + sin( πx u(x ) u(x + u(x 5 ) h + u(x = 1 + sin( πx 4 u(x 4) u(x 5 ) + 4 h + u(x 5 ) = 1 + sin( πx 5 Putting all the constants on the right hand side and collect terms, we get ( ) ( ) h + 1 u(x 1 ) h u(x ) = 1 + sin( πx 1 + h ( ) ( ) ( ) h u(x 1 ) + h + 1 u(x ) h u(x ) = 1 + sin( πx ( ) ( ) ( ) h u(x ) + h + 1 u(x ) h u(x = 1 + sin( πx ( ) ( ) ( ) h u(x ) + h + 1 u(x h u(x 5 ) = 1 + sin( πx 4 ( ) ( ) h u(x + h + 1 u(x 5 ) = 1 + sin( πx 5 + 1 h 1

We can also multiply by h on both sides: ( + h )u(x 1 ) u(x ) = h + h sin( πx 1 + u(x 1 ) + ( + h )u(x ) u(x ) = h + h sin( πx u(x ) + ( + h )u(x ) u(x = h + h sin( πx u(x ) + ( + h )u(x u(x 5 ) = h + h sin( πx 4 u(x + ( + h )u(x 5 ) = h + h sin( πx 5 + 1 Write in matrix form + 1 0 0 0 u(x h h 1 ) + 1 0 0 h h h u(x ) 0 + 1 0 h h h u(x 0 0 + 1 ) = u(x h h h 0 0 0 + 1 u(x h h 5 ) or 1 + sin( πx 1 + h 1 + sin( πx 1 + sin( πx 1 + sin( πx 4 1 + sin( πx 5 + 1 h + h 0 0 0 u(x 1 ) h (1 + sin( πx 1 + h 4 0 0 u(x ) )) + h (1 + sin( πx 0 + h ) 0 u(x 0 0 + h ) = h (1 + sin( πx ) u(x h (1 + sin( πx 4 0 0 0 + h ) u(x 5 ) h (1 + sin( πx 5 4 )) + 1. Matlab function that generates the tridiagonal system with input n: function [A,b] = tridiagsys(n) % Generate the tridiagonal system for given differential equation % Input variables % - n: The number of steps % Output variables % - A: The tridiagonal matrix % - b: The vector of right hand side (rhs) % Functions Called % None % Given differential equation % -u (x) + u(x) = 1 + sin(pi*x/4), 0 <= x <= % u(0)=, u()=4 % Calculate h and x(interior points only, not points) h = (-0)/n; x = h:h:-h;

% Allocate vectors A = zeros(n-1,n-1); b = zeros(n-1,1); % Fill in the matrix for i = 1:n-1 % Diagonal A(i,i) = /h^ + 1; if i >1 % Lower diagonals A(i,i-1) = -/h^; % Upper diagonals A(i-1,i) = -/h^; % Calculate rhs vector b(1) = 1 + sin(pi*x(1)/4) + /h^; for i=:n- b(i) = 1 + sin(pi*x(i)/4); b(n-1) = 1 + sin(pi*x(n-1)/4) + 1/h^; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Code that calls the function with inputs looping over an input vector of n values: % Generate the tridiagonal system of the differential equation % -u (x) + u(x) = 1 + sin(pi*x/4), 0 <= x <= % u(0)=, u()=4 % for a vector of n values % vector of n n = [,8,10]; % loop over n for i = 1:length(n); [A,b] = tridiagsys(n(i)); display(a) display(b). There is only one root between [a k1, b k1 ]. The midpoint of the interval is a k1+b k1. Let the root be r. If our guess ˆx k is in the left half of the interval, i.e. ˆx k [a k1, a k1+b k1 ), the worst case would be when r = b k1, and the error in this case would be e = b k1 ˆx k > b k1a k1. Similarly, if our guess ˆx k is in the right half of the interval, i.e. or ˆx k ( a k1+b k1, b k1 ], the

worst case would be when r = a k1, and the error in this case would be e = a k1 ˆx k > b k1 a k1. If our guess ˆx k is at the midpoint, i.e. ˆx k = a k1+b k1, then the worst case is when r = a k1 or r = b k1, and in either case the error e = b k1a k1 is less than that of other guesses. 4. Perform steps of bisection method to find the root of f(x) = exp[x sin(x)], starting with a 0 = and b 0 =. f(a 0 ) =.9545 f(b 0 ) = 18.995 f(a 0 ) f(b 0 ) < 0. There is a root between a 0 and b 0. ˆx 1 = c 1 = a 0 + b 0 f(c 1 ) = = + = 0 f(c 1 ) f(b 0 ) < 0. There is a root between c 1 and b 0. a 1 = c 1 = 0 b 1 = b 0 = ˆx = c = a 1 + b 1 f(a 1 ) = f(b 1 ) = 18.995 f(c ) = 0.185 = 0 + = 1 f(c ) f(a 1 ) < 0. There is a root between c and a 1. a = a 1 = 0 b = c = 1 ˆx = c = a + b f(a ) = f(b ) = 0.185 f(c ) = 1.170 = 0 + 1 = 0.5 f(c ) f(b ) < 0. There is a root between c and b. a = c = 0.5 b = b = 1 ˆx 4 = c 4 = a + b = 0.5 + 1 5. Matlab code that performs bisection method. = 0.75 function [f] = functioneval(x) % Compute the function value % Input variables 4

% - x: the point where function value is calculated % Output variables % - f: function value at point x % Functions Called % - None f = - exp(*x - sin(x)); A function that performs bisection method: function [root, f, n] = bisection_mthd(a,b,eps) % The objective of this code is to compute the root of a % function using the bisection method. % Input variables % - a,b: the starting points of the bisection algorithm % - eps: the desired error % Output variables % - root: The approximation of the root of the function after n iterations (xhat_n) % - f: The value of the funtion at xhat_n % - n: The number of function evaluations % Functions Called % - functioneval: This function returns the evaluation of f at x % Initial function evaluations fa = functioneval(a); fb = functioneval(b); % Check if starting point is compatible if (fa*fb > 0) error( Initial points are incompatible ); % Determine number of steps corresponding to desired error n = ceil((log(b-a) - log(eps))/log()); % midpoint of [a_0,b_0] c = a + 0.5*(b-a); % Algorithm. of Textbook for i = 1:n-1 fc = functioneval(c); if (fa*fc < 0) b = c; fb = fc; elseif (fa*fc > 0) a = c; fa = fc; else %fa*fc = 0 root = c; 5

root = (a+b)/; f = functioneval(root); % there is one function evaluation in each iteration from step to step n; % and there are two function evaluations in the beginning % number of function evaluations = n+1 n= n+1; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Results: >> [xhat_n,fxhat_n,n]= bisection_mthd(-,,10^(-5)) xhat_n = 0.9585 fxhat_n = n = -8.51e-0 0