Skip to content

Latest commit

 

History

History

SecantAndBisectionMethods

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Project 3: Secant and Bisection Methods

This project was assigned for the Numerical Methods for Electrical Engineering (EE 242) course in the Spring 2021 semester.

Run on Terminal

g++ main.cpp -o test
test 𝑎n 𝑎𝑛-1 ... 𝑎0 𝑥0 𝑥1 𝑡𝑜𝑙
(e.g. test 2 2 -7 1 -7 1.5 1.8 0.001)

Project Goals

In this project, you will be implementing secant and bisection algorithms to solve 𝑓(𝑥) = 0 for any given polynomial f.

Your program should take the coefficients of the function, initial guesses, and the tolerance value as command-line arguments and return the resulting values of x as well as the numbers of iterations for each method. For the bisection method, your program should give the warning that your algorithm doesn’t work if the signs of initial guesses are the same. You should implement both methods separately first. Then you should use a hybrid method where you start with bisection methods for the first two iterations and then continue with the secant method for the rest of the iterations. Your program should print out the number of iterations required for each of the 3 methods (i.e., bisection, secant, and hybrid). If the number of iterations for each method exceeds 15, your program should be terminated and it should give notes as “the number of iterations exceeded the threshold.”

Project Details

  • You have n+1 command-line inputs for the coefficients of 𝑓(𝑥) = 𝑎𝑛𝑥𝑛 + 𝑎𝑛-1𝑥𝑛-1 + ⋯ + 𝑎1𝑥 + 𝑎0 in the order from 𝑎n to 𝑎0. Use dynamically allocated memory to store these.
  • You have 3 more command line arguments for the initial guesses 𝑥0, 𝑥1 (𝑥1 > 𝑥0), and the tolerance value 𝑡𝑜𝑙.