Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my code but it is not working double c1=0; double c2=0; double c3=0; double c4=0; double c5=0; double c0=0; int counter_1=0; int counter_2=0;

This is my code but it is not working

double c1=0;

double c2=0;

double c3=0;

double c4=0;

double c5=0;

double c0=0;

int counter_1=0;

int counter_2=0;

double iGuess=0;

double Vaule_y=0;

double gfc=0;

printf("This program os to find one root of the 5th-order polynomial using Newton-Rhapson method. ");

printf("c5x^5 + c4x^4 + c3x^3 + c2x^2 + c1x + c0 ");

printf("Enter polynomial coefficeints: c5 c4 c3 c2 1 c0 in this order: ");

scanf(" %lf%lf%lf%lf%lf%lf", &c5,&c4,&c3,&c2,&c1,&c0);

printf("Your polynomial is, ");

PrintPolynomial(c5,c4,c3,c2,c1,c0);

for (counter_1 = 1; counter_1

iGuess = InitailGuessNum(counter_1);

gfc = iGuess;

for(counter_2 = 1; counter_2

Vaule_y = c5 * pow(gfc,5) + c4*pow(gfc,4) + c3 * (gfc,3) + c2 * (gfc,2) + c1 * gfc+ c0;

if(fabs(Vaule_y)

printf("One of the roots of this polynomial is %.5f ", gfc);

printf("Staring from an initial guess of x= %.1lf, this answer was obtained in %d iterations. ",iGuess, (counter_2-1));

counter_2=501;

}

else if (counter_2

gfc = NewXval(gfc,Vaule_y,c5,c4,c3,c2,c1);

}

else{

printf("The initial guess of x = %.1f failed to converge to a solution; roots may be complex ", iGuess);

}

}

}

return 0;

}

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

2.1 Newton-Raphson Algorithm: Write a program that prompts the user to input the coefficients c5, c4, C3c2 The 5th order polynomial has the form , co of a 5th-order polynomial We know that the first derivative of y with respect to x is dx We can use this information to find the roots of the polynomial. The basic idea, in the Newton-Raphson method, is as follows: (a) Given an initial guess x, and polynomial coefficients c, calculate y (b) Check to see if y is close enough to zero, i.e. within some small tolerance close to zero (i) If so then terminate. Algorithm has converged! (ii) If not then continue (c) Use the current value of x to calculate y' (d) Create a new guess for x using the update formula x-x- (e) Increment a counter to count the number of algorithm iterations (f) Check to see if the number of iterations has exceeded a predetermined count limit (say 500) (i) If so then terminate. Algorithm has failed! (ii) If not then return to step a We would like to use 7 different initial guesses to test the Newton-Raphson algorithm; XInitialGuess -10000,-1000,-100, 0, 100, 1000, 10000) Thus your code will need to loop around the Newton-Raphson algorithm 7 times, once for each initial guess This same information is described in the flow chart below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

3. The group answers the questions.

Answered: 1 week ago