### Problem With Secant Method

Can someone help me find the error of this code? it displays wrong results. Here is a sample output usuing the polynomial x^2-5x+2.

 ``` Enter the order of the equation: 2 Enter the coefficient of x^2: 1 Enter the coefficient of x^1: -5 Enter the constant term: 2 Enter first initial guess: 4 Enter second initial guess: 5 Set maximum number of iterations: 10 __________________________________ k x[k] error __________________________________ 0 4 -2 1 5 2 2 0 2 3 1.#INF -1.#IND 4 -1.#IND -1.#IND 5 -1.#IND -1.#IND 6 -1.#IND -1.#IND 7 -1.#IND -1.#IND 8 -1.#IND -1.#IND 9 -1.#IND -1.#IND _________________________________ The root is approximately: -1.#IND0000000000000 With error of: -1.#IND0000000000000 ```

and here is my code

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103`` ``````#include #include #include using namespace std; int p; const int MAX = 1000; double coeff[MAX]; double f(double); int main() { double guess1, guess2; int imax; double x[MAX]; //Get Function cout << "\tEnter the order of the equation: "; cin >> p; for(int i = p; i > 0; i--) { cout << "\tEnter the coefficient of x^" << i << ": "; cin >> coeff[i]; } cout << "\tEnter the constant term: "; cin >> coeff[0]; cout << endl; //Final inputs cout << "\tEnter first initial guess: "; cin >> guess1; cout << "\tEnter second initial guess: "; cin >> guess2; cout << "\tSet maximum number of iterations: "; cin >> imax; //assigning guesses if(guess2>guess1) { x[0] = guess1; x[1] = guess2; } else { x[0] = guess2; x[1] = guess1; } //the heart of secant method for(int i = 2; i
 ``1234`` `````` for(int i = 2; i
`x[2]' is uninitialized.
got it men! THANK YOU SO MUCH!
Topic archived. No new replies allowed.