CS314 Numerical Analysis

Homework 2

The Solutions of Nonlinear Equations f(x) = 0

Part 1: Problems

1. Do the following problems. Write the procedure and solutions clearly and include also the questions in your paper. The problem numbers and page numbers match in both the third and fourth edition of the book.

Page 50 Problem 3a
Page 61 Problem 6 and 10
Page 86 Problem 7 and 10

Important: The problems are due on Friday June 28th during class.

Part 2. Programming

Read first the tutorial Matlab Primer by Kermit Sigmon (University of Florida)(PDF) (HTML).

Write a program with the following characteristics.

You can start by downloading the file in lab2-src.zip to your computer. This file contains the files in lab2-src that can help you to start your project.

1. Write a program in matlab that asks for a function f(x), and an interval x0, x1, and plots the graph.

2. After ploting the graph, the progam will ask you if you

1) Do you want to plot another function?,
or find the solution to f(x)=0 using
2) Bisection,
3) Regula-Falsi,
4) Newthon-Raphson,
5)Secant Method., or
6) Exit.


3. If the method chosen is Bisection or Regula-Falsi, the program should ask for an interval a, b. If the method chosen is Newthon-Rapson, the program will ask for a starting point a. If the method chosen is the secant method, the program will ask for the initial a, b values for x. In the Newthon-Rapson method use the numerical differentiation we covered in class using the eps constant defined in Matlab for the deltax.

4. The methods will converge when abs(f(x)) < eps, where eps is a constant defined in Matlab.

5. The method should print at each iteration the values of x, f(x) and the iteration number.

6. At the end of executing the method, your program shoud plot f(x) again in the interval x0, x1 and also it  should plot with little crosses (see plot in the Matlab documentation) the values of x and f(x) at each iteratation. You may store all the values of x, f(x) in a vector at each iteration, and then plot them all at once at the end of the execution of the method together with f(x).

8. If the method does not converge after 100 iterations, then the method should exit and print the error "Method did not converge" and then print the menu in 2. again.

Use your program to find the solutions for the equations described next. Write the value of x, f(x) And the how many iterations it took to converge.For Newthon Rapson use the middle point of a0, b0 as starting point. For the secant method use a0, b0.

ex -2 -x = 0 [a0,b0]=[-2.4, -1.6]

 
Method x f(x) #iterations
Regula Falsi        
Bisection      
Newthon Raphson      
Secant      

cos(x) + 1 - x = 0 [a0,b0]=[0.8, 1.6]


 
Method x f(x) #iterations
Regula Falsi        
Bisection      
Newthon Raphson      
Secant      

ln(x) - 5 + x = 0 [a0,b0]=[3.2, 4.0]


 
Method x f(x) #iterations
Regula Falsi        
Bisection      
Newthon Raphson      
Secant      

x3 -3x -2 (Find a suitable interval)


 
Method x f(x) #iterations
Regula Falsi        
Bisection      
Newthon Raphson      
Secant      

Write these tables  in a file called solutions.html
 

Turn in

To turnin create a directory "hw2" and store in it both the solutions.html and m-files. Then zip the file and mail it as an attachment to cs314-ta@cs.purdue.edu.

The deadline for this programming assignment is Monday July 8th at 11:59pm.
E-mail your questions to cs314-ta