Announcements

This unit deals with user defined functions in C++.  Functions are procedures which augment the main function of our program and can accomplish certain tasks on their own and then transfer their results to the main ( or to other functions) and/or output their results to files or to the screen.  They are in many ways similar to the functions of the mathematical library, but there is more to them. Functions with a single return, multiple returns and no return will be discussed .

 In this unit we will also learn how to approximate roots of nonlinear and transcendental equations .  There are many root-finding methods. Some of them are of the "bracketing type" some are not. Considering single equations we may mention the techniques: Bisection, False Position, Van Wijngaarden-Dekker-Brent method, Newton-Raphson, Secant, Deflation of Polynomials, Muller's Method, Jenkins-Traub, Lehmer-Schur method and many others.

We all hope that some of our students will come up with their own efficient methods when challenged with a particular problem. In this unit we will discuss Bisection, Newton's, and Secant methods

 Reading Assignments
Mandatory:  Book 1; Pages 157 - 180 & 405 - 413 

 Subtopics — Notes/ Examples:


User defined functions in C++

Numerical Methods: Root finding techniques

 

 Tasks:


Task #1 Write a program which consists of the main function and the function int facto( int k), which calculates the factorial of k ( k! = 1*2*3*4*5*.....k ). The main should prompt for and read k and it should output k and k!

Task #2 Write a program which consists of the main function and the function int factorials( int k), which calculates all the factorials from 1! to k! and also outputs them to the screen in the form of a good looking table. The main should prompt for and read k and it should simply call the function factorials.

Task #3 Consider Task #2 of the previous unit, where you had to calculate the force, given the value of the parameter a and the value of the elongation delta. Do the following task: write a program which generates two tables ( use iomanip.h to make the output look good). The first table will list elongation vs. force while the value of the parameter a remains fixed at 1 mm. The elongation should vary from zero to 4 mm. The second table will list parameter vs. force as the elongation remains fixed at 2.5 mm. The parameter will vary from zero to 4 mm. Use a user defined function to calculate the force. ANSWER

Task #4 Write a program for the secant method of root finding. Start with x0=1 and x1=2 in order to obtain the positive root of x^2-5=0 . Of course your answer should converge to 2.236068

Start working on HW5 and PA5.


Jacob Y. Kazakia © 2001 All rights reserved
7