Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

poly_main.c #include #include #include #include polynomial.h int main() { int n = 4; float p[] = {1, 2, 3, 4}; int m = 3; float

image text in transcribedimage text in transcribedpoly_main.c

#include

#include

#include

#include "polynomial.h"

int main()

{

int n = 4;

float p[] = {1, 2, 3, 4};

int m = 3;

float x[] = {0,1,10};

// test display and horner functions

int i;

for (i=0; i

printf("P(%.2f)=", x[i]);

display_polynomial(p, n, x[i]);

printf("=");

printf("%.2f ", horner(p, n, x[i]));

}

// test bisection function

float a=-2, b=2;

float pa = horner(p, n, a);

printf("P(%.2f)=%.2f ", a, pa);

float pb = horner(p, n, b);

printf("P(%.2f)=%.2f ", b, pb);

if (pa * pb

float root = bisection(p, n, a, b);

printf("root=%.2f ", root);

printf("P(%.2f)=%.2f ", root, horner(p, n, root));

}

else {

printf("have the same sign on both sides ");

}

return 0;

}

Write a C program, polynomial.h, containing the following functions: 1. void display_polynomial (float p[], int n, float x), which prints the polynomial in format like p[0] *x^{n-1} + p[1] *x^{n-2} +...+ p[n-2] *x^1 + p[n-1]*x^0 with 2 digits after the point, e.g., 1.00*10.00^3+2.00*10.00^2+3.00*10.00-1+4.00*10.00-0 float horner (float p[], int n, float x), which computes and returns the value of the following polynomial P(x) of order n and coefficients p[0], ..., p[n-1]. 2. P(x) = = P[O] * xn-1 + p[1] * 2" +... .+p[n 2] *x++p[n 1] * * It is required to use Horner's algorithm (supplementary link). 3. float bisection (float p[], int n, float a, float b), which finds an approximate real root c in interval [a, b] of polynomial P(x), using the bisection method (supplementary link). Use the fault tolerant 1e-6 (or 0.000001) as a stop condition, i.e., if xo is the actual root, stop the iteration if |c-x0| #include #define EPSILON le-6 void display_polynomial(float p[], int n, float x) { // your implementation } float horner (float p[], int n, float x) { // your implementation } float bisection(float p[], int n, float a, float b) { // your implementation }

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 Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions

Question

=+1. What is the brand's character or personality?

Answered: 1 week ago