Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program for root finding by bisection for a polynomial. Your program s

ID: 3748761 • Letter: W

Question

Write a C program for root finding by bisection for a polynomial. Your program should ask for the coefficients of a polynomial up to 4th order (5 coeffs) starting from the lowest order term and assuming that once a zero is encountered that all remaining coefficients are also zero. Concretely, we are root finding the polynomial of the form where your program should ask the user for the coefficients a e in order, stopping when one is zero As an example if the third coefficient is 0 then the program should stop asking for coefficient inputs and assume that the polynomial is linear. Talk to your TA if this requirement is confusing Your program should follow the following structure and requirements 1. Take Inputs Starting point: a Ending point: b Error Tolerance: TOL . Polynomial Coefficients until a 0 is encountered 2. Check Conditions: . All inputs are of the correct type . The starting point occurs before the ending point a

Explanation / Answer

#include double errorTolerance; int a, b, c, d, e; double func(double x) { return a + b*x + c*x*x + d*x*x*x + e*x*x*x*x; } // Prints root of func(x) with error of EPSILON void bisection(double start, double end) { if (func(start) * func(b) >= 0) { printf("There is no root between %lf and %lf ", start, end); return; } double mid; while ((end-start) >= errorTolerance) { // Find middle point mid = (start+end)/2; // Check if middle point is root if (func(mid) == 0.0) break; // Decide the side to repeat the steps else if (func(mid)*func(start) < 0) end = mid; else start = mid; } printf("The value of root is : %lf", mid); } // Driver program to test above function int main() { double start, end; printf("Enter coefficient a: "); scanf("%d", &a); if(a != 0) { printf("Enter coefficient b: "); scanf("%d", &b); if(b != 0) { printf("Enter coefficient c: "); scanf("%d", &c); if(c != 0) { printf("Enter coefficient d: "); scanf("%d", &d); if(d != 0) { printf("Enter coefficient e: "); scanf("%d", &e); } } } } printf("Enter starting point: "); scanf("%lf", &start); printf("Enter end point: "); scanf("%lf", &end); printf("Enter Error tolerance: "); scanf("%lf", &errorTolerance); bisection(start, end); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote