Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a C program to find the zero of a mathematical function f(x) around a given point x 0 , using the Newton Raphson method.

write a C program to find the zero of a mathematical function f(x) around a given point x0, using the Newton Raphson method. We consider f(x) as a polynomial function of degree n, such that n is less than or equal to 3.

The overall program MUST have the following 2 functions:

A C function evalFun (.), that computes P(x) for a given x. This function evalFun(), takes as input:

the degree of the polynomial n, where n is an integer n 3,

the real coefficients a3, a2, a1, a0 and x (all of type double), such that some coefficients may be equal to zero.

The function should return the value of P(x).

Note that since we are dealing with a polynomial function in equation (1), the same function code evalFun() can be used to evaluate both f(x) and its derivative f(x) in equation (2), below:

Function newtonRaphsonMethod() is to find the zero of the polynomial function f(x) given an initial value x0 using the Newton Raphson algorithm. This function (newtonRaphsonMethod ()) should have as input

the estimated initial value x0, and

the accuracy .

It should return the root or zero of the function, and the number of iterations required to find this root. The number of iterations is number of times the loop has run. A condition should be set on the number of iterations such that if the number of iterations exceeds 100, the loop should stop and return -1. The main function should check the value returned by the function and decides whether the result is valid or not.

The program should be general to handle all types of polynomial functions with degree n 3.

For invalid input, the program should display an error message and prompts the user to enter a new choice or value again.

The program should quit only when the user requests it.

To make the polynomial coefficients (a3, a2, a1, a0) known in all functions they should be declared as global variables, i.e. before the main function., and should not be redeclared in any other function.

The main function should consist only of function calls (you should not write long code in main).

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 Machine Performance Modeling Methodologies And Evaluation Strategies Lncs 257

Authors: Francesca Cesarini ,Silvio Salza

1st Edition

3540179429, 978-3540179429

More Books

Students also viewed these Databases questions