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

PLEASE WRITE CODE IN C PLEASE WRITE IN CODE C much thanks! Finding Roots of Equa

ID: 3587903 • Letter: P

Question

PLEASE WRITE CODE IN C

PLEASE WRITE IN CODE C

much thanks!

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<stdio.h>

#include<math.h>

double myfunc(double x)

{

return x*sin(x)+cos(x);

}

int eval-poly( int array[], int limit, int degree)

{

int value=array[0];

prinf(“given polynomial is:”);

for( int count=1; count<limit; count++)

{

if(degree<0)

{

break;

}

if(array[i]>0)

printf(“+”);

else if (array[i]<0)

printf(“-”);

else

printf(“ ”);

Printf(“%dx^%d “, abs(array[i]),degree--)

}

for( int count=1; count<limit; count++)

value= (value* degree)+array[count];

Return value;

}

int main(int argc, char *argv[])

{

int I;

int array[];

int degree, limit;

degree=argc-4;

limit=argc-3;

for(i=1; i<=limit;i++)

array[i]=atoi(argv[i]);

printf(“value of polynomial: %d ”, eval-poly(array,limit,degree));

double lpt,rpt,mpt,epsilon=0.0000001;

double mval,rtval,root;

lpt=atof(argv[limit+1]);

rpt=atof(argv[limit+2]);

do

{

mpt=(lpt+rpt)/2;

rtval=myfunc(rpt);

mval=myfunc(mpt)

if(rtval*mval>=0)

rpt=mpt;

else

lpt=mpt;

}while((rpt-lpt)>epsilon);

root=(rpt+lpt)/2;

Printf(“ root is:”%15.101f ”,root);

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