Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C program, named bisection.h , containing the following functions. Function float horner(float *p, int n, float x) Function float bisection(float *p, int n,
Write a C program, named bisection.h, containing the following functions.
- Function float horner(float *p, int n, float x)
- Function float bisection(float *p, int n, float a, float b) computes a real root of the polynomial function f(x) = p[0]xn-1 + p[1]xn-2 ++ p[n-2]x1 + p[n-1]x0 between interval [a, b] by bisection method when f(a)*f(b) < 0. Use the fault tolerant 1e-6 (or 0.000001) as a stop condition, i.e., if x0 is the actual root and x is a approximate to x0, stop the iteration if |x-x0|<1e-6 or |f(x)| < 1e-6.
Use the provided main program to test the above functions.
Main Program
#include "bisection.h" int main(int argc, char* args[]) { float p[] = {1, 2, 3, 4}; int n = 4; float a = -2, b = 2; float pa = horner(p, n, a); float pb = horner(p, n, b); printf("f(%f): %f ", a, pa); printf("f(%f): %f ", b, pb); if (pa * pb < 0) { float r = bisection(p, n, a, b); printf("root: %f ", r); printf("f(%f): %f ", r, horner(p, n, r)); } return 0; }
Code so Far: bisection.h
#include#include float horner(float *p, int n, float x); float bisection(float *p, int n, float a, float b); float horner(float *p, int n, float x) { // implementation } //bisection method implementation float bisection(float *p, int n, float a, float b) { // implementation }
public test
f(-2.000000): -2.000000 f(2.000000): 26.000000 root: -1.650629 f(-1.650629): 0.000001
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started