Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

polynomial_main.c: #include #include #include #include polynomial.h void display_polynomial(float p[], int n, float x) { int i; for (i=0; i EPSILON && i !=0) printf(+); printf(%.2f*%.2f^%d,

image text in transcribedimage text in transcribed

polynomial_main.c: #include #include #include #include "polynomial.h"

void display_polynomial(float p[], int n, float x) { int i; for (i=0; i EPSILON && i !=0) printf("+"); printf("%.2f*%.2f^%d", p[i], x, n-i-1); } } int main(int argc, char *argv[]) { 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

return 0; }

polynomial.h:

/* * your program signature */ #ifndef POLYNOMIAL_H #define POLYNOMIAL_H #include #include #define EPSILON 1e-6 float horner(float p[], int n, float x) { // your implementation } // compute the derivative of polynomial p[], and output to d[] void derivative(float p[], int n, float d[]) { // your implementation } // Use Newton's method to find and return a root of polynomial of p[] float newton(float p[], int n, float x0) { // your implementation } #endif
Write a C program, polynomial.h, containing the following polynomial operation functions: 1. float horner(float p[], int n, float x ), which computes and returns the value of the following (n1)-th degree polynomial p(x) of coefficients p[0],,p[n 1]. p(x)=p[0]xn1+p[1]xn2++p[n2]x1+p[n1]x0 It is required to use Horner's algorithm (supplementary link). 2. void derivative(float p[], int n, float d[], which computes the derivative of input (n-1)-th degree polynomial by p[], output the derivative of (n2)-th degree polynomial to array d[]. The derivative of the above polynomial p(x) is as follows. p(x)=(n1)p[0]xn2+(n2)p[1]xn3++p[n2]x0 3. float newton(float p[], int n, float x ), which finds an approximate real root x of polynomial p(x) using the Newton's method with start position x. Use the fault tolerant 1e6 (or 0.000001 ) as a stop condition, i.e., if r is the actual root, stop the iteration if xr<>

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

Students also viewed these Databases questions