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

PLEASE WRITE IN C Code PLEASE WRITE IN C Code Finding Roots of Equations This as

ID: 3587451 • Letter: P

Question

PLEASE WRITE IN C Code

PLEASE WRITE IN C Code

Finding Roots of Equations This assignment is designed to teach you how to solve two of the most common problems in numerical methods: (1) evaluating polynomial functions and (2) optimization. The problem Your application will take a series of command-line arguments Cn, Cn-1,Cn-2.",c1,co, a, b] as floating point values. The values co through cn will be the coefficients of a degree n polynomial p(x). The coefficients are specified in the order of decreasing power. For example, co is a constant and Cn is the coefficient of x". The last two values, a and b, will specify the interval over which your application will search for a root and display the following a) The polynomial (make it as readable as possible) b) The root rb = |p(x) 0 according to the bisection method c) The number of iterations required to locate the root using the bisection method d) The root xlp(x) 0 according to Newton's method e) The number of iterations required to locate the root using Newton's method Your code will operate under the following constraints 1) 2) Use Horner's algorithm to calculate p(x) and p'(x) as necessary Evaluate the root to the best possible precision (using 64-bit floating point values) the exact root may not be representable how will you find the value closest to the root? a. b. a+b 3) Newton's method will start with x0-- 4) Return an error if no root is found within the interval [a, b

Explanation / Answer

#include <iostream>
using namespace std;

// returns value of poly[0]x(n-1) + poly[1]x(n-2) + .. + poly[n-1]
int horner(int poly[], int n, int x)
{
int result = poly[0]; // Initialize result

// Evaluate value of polynomial using Horner's method
for (int i=1; i<n; i++)
result = result*x + poly[i];

return result;
}

// Driver program to test above function.
int main()
{
// Let us evaluate value of 2x3 - 6x2 + 2x - 1 for x = 3
int poly[] = {2, -6, 2, -1};
int x = 3;
int n = sizeof(poly)/sizeof(poly[0]);
cout << "Value of polynomial is " << horner(poly, n, x);
return 0;
}

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