You are on page 1of 1

Andrew Wytsma ENGG 407 Assignment #1 a) Here, the bisection method was utilised to obtain the interest rate.

A slight modification needed to be made to the equation in order for it to be in the correct form (the same modification was applied to parts b, and c as well). The equation was given as P I A= ((1 + ) N 1) , but we need the function in the form f(I) = _____. In this case we I /12 12 are finding the root of the equation so the equation was modified to P I f (I ) = ((1 + ) N 1) A . The given values were substituted for A, P, and N. The I /12 12 program then prompts the user for initial guesses for the root of the equation. Using a graphical method, a range of plausible values that would have the function cross the x-axis was determined. If the user enters values outside the suggested range, the program will prompt the user to re-enter their values. The initial root is calculated using the bisection equation. The function is then evaluated at each of the three points. Using an if/else selection structure, the bisection algorithm is performed once. It is important that the variable err(which represents error), is set to the arbitrary value of 100. Using a while loop, the bisection algorithm is repeated until the error is reduced to zero. This method allows for a near exact solution to the problem. After the root is determined, it is displayed on the screen. b) To determine the required interest rate using the secant method, the function was again modified, and the values were substituted. The program initially prompts the user for 2 arbitrary values with which it will begin the algorithm. Here, xo will represent the current guess, and xminus represents the previous guess. The secant algorithm is performed one time to determine a new x value (xn in this case), as well as an initial error calculation. Again a while loop is used to reduce the error to zero, and the final result is displayed on screen. c) Finally, Newtons method was used to find a root to the equation. Again the modified function was used. The first derivative of the function was taken using Matlabs built in diff function. The program prompts the user for an initial guess for the root, and uses this value to perform Newtons algorithm one time. After the algorithm is performed the error is calculated. Once again, a while loop was used to reduce the error to zero. The final result is printed on the screen. In conclusion, Newtons method was the easiest algorithm to implement in Matlab, given that the software includes a built in function that will take the derivative of a function automatically. But if one were to create the program using C++, the secant method would most likely be favourable. The bisection method requires more code, because the users guess may not be chose completely arbitrarily.

You might also like