Question
use C programing to solve the following exercise.
Compute a root of the equation 4. (20 points) e-3 cos(x)-o using (a) Bisection Method between 0 and I. (b) Newton Method usin
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part-A:

the program is:

#include<stdio.h>
#include<math.h>

double func(double x)
{
return exp(x)-3*cos(x);
}

double e=0.00001;
double c;

void bisection(double a,double b)
{
if(func(a) * func(b) >= 0)
{
printf("Incorrect a and b");
return;
}

c = a;

while ((b-a) >= e)
{
c = (a+b)/2;
if (func(c) == 0.0){
printf("Root = %lf\n",c);
break;
}
else if (func(c)*func(a) < 0){
printf("Root = %lf\n",c);
b = c;
}
else{
printf("Root = %lf\n",c);
a = c;
}
}
}

int main()
{
double a,b;
a=0;
b=1;

printf("The function used is e^x-3cos(x)\n");
printf("a = %lf\n",a);
printf("b = %lf\n",b);
bisection(a,b);
printf("\n");
printf("Accurate Root calculated is = %lf\n",c);

return 0;
}

The output is:

The function used is e^x-3cos(x)

a = 0.000000
b = 1.000000
Root = 0.500000
Root = 0.750000
Root = 0.875000
Root = 0.812500
Root = 0.781250
Root = 0.765625
Root = 0.773438

Accurate Root calculated is = 0.773438

Part-B:

#include<stdio.h>
#include<math.h>
float f(float x)
{
return exp(x)-cos(x);
}
float df (float x)
{
return exp(x)-cos(x);
}
main()
{
int itr, maxmitr;
float h, x0, x1, allerr;
printf("\nEnter x0, error and iterations\n");
scanf("%f %f %d", &x0, &allerr, &maxmitr);
for (itr=1; itr<=maxmitr; itr++)
{
h=f(x0)/df(x0);
x1=x0-h;
printf(" Iteration no. %d, x = %f\n", itr, x1);
if (fabs(h) < allerr)
{
printf("After %d iterations, root = %f\n", itr, x1);
return 0;
}
x0=x1;
}
printf(" The required solution does not converge \n");
return 1;
}

Output:

Enter x0, allowed error and maximum iterations
1
0.0001
80
At Iteration no. 1, x = 0.000000
At Iteration no. 2, x = -1.#IND00
At Iteration no. 3, x = -1.#IND00
At Iteration no. 4, x = -1.#IND00
At Iteration no. 5, x = -1.#IND00
At Iteration no. 6, x = -1.#IND00
At Iteration no. 7, x = -1.#IND00
At Iteration no. 8, x = -1.#IND00
At Iteration no. 9, x = -1.#IND00
At Iteration no. 10, x = -1.#IND00
At Iteration no. 11, x = -1.#IND00
At Iteration no. 12, x = -1.#IND00
At Iteration no. 13, x = -1.#IND00
At Iteration no. 14, x = -1.#IND00
At Iteration no. 15, x = -1.#IND00
At Iteration no. 16, x = -1.#IND00
At Iteration no. 17, x = -1.#IND00
At Iteration no. 18, x = -1.#IND00
At Iteration no. 19, x = -1.#IND00
At Iteration no. 20, x = -1.#IND00
At Iteration no. 21, x = -1.#IND00
At Iteration no. 22, x = -1.#IND00
At Iteration no. 23, x = -1.#IND00
At Iteration no. 24, x = -1.#IND00
At Iteration no. 25, x = -1.#IND00
At Iteration no. 26, x = -1.#IND00
At Iteration no. 27, x = -1.#IND00
At Iteration no. 28, x = -1.#IND00
At Iteration no. 29, x = -1.#IND00
At Iteration no. 30, x = -1.#IND00
At Iteration no. 31, x = -1.#IND00
At Iteration no. 32, x = -1.#IND00
At Iteration no. 33, x = -1.#IND00
At Iteration no. 34, x = -1.#IND00
At Iteration no. 35, x = -1.#IND00
At Iteration no. 36, x = -1.#IND00
At Iteration no. 37, x = -1.#IND00
At Iteration no. 38, x = -1.#IND00
At Iteration no. 39, x = -1.#IND00
At Iteration no. 40, x = -1.#IND00
At Iteration no. 41, x = -1.#IND00
At Iteration no. 42, x = -1.#IND00
At Iteration no. 43, x = -1.#IND00
At Iteration no. 44, x = -1.#IND00
At Iteration no. 45, x = -1.#IND00
At Iteration no. 46, x = -1.#IND00
At Iteration no. 47, x = -1.#IND00
At Iteration no. 48, x = -1.#IND00
At Iteration no. 49, x = -1.#IND00
At Iteration no. 50, x = -1.#IND00
At Iteration no. 51, x = -1.#IND00
At Iteration no. 52, x = -1.#IND00
At Iteration no. 53, x = -1.#IND00
At Iteration no. 54, x = -1.#IND00
At Iteration no. 55, x = -1.#IND00
At Iteration no. 56, x = -1.#IND00
At Iteration no. 57, x = -1.#IND00
At Iteration no. 58, x = -1.#IND00
At Iteration no. 59, x = -1.#IND00
At Iteration no. 60, x = -1.#IND00
At Iteration no. 61, x = -1.#IND00
At Iteration no. 62, x = -1.#IND00
At Iteration no. 63, x = -1.#IND00
At Iteration no. 64, x = -1.#IND00
At Iteration no. 65, x = -1.#IND00
At Iteration no. 66, x = -1.#IND00
At Iteration no. 67, x = -1.#IND00
At Iteration no. 68, x = -1.#IND00
At Iteration no. 69, x = -1.#IND00
At Iteration no. 70, x = -1.#IND00
At Iteration no. 71, x = -1.#IND00
At Iteration no. 72, x = -1.#IND00
At Iteration no. 73, x = -1.#IND00
At Iteration no. 74, x = -1.#IND00
At Iteration no. 75, x = -1.#IND00
At Iteration no. 76, x = -1.#IND00
At Iteration no. 77, x = -1.#IND00
At Iteration no. 78, x = -1.#IND00
At Iteration no. 79, x = -1.#IND00
At Iteration no. 80, x = -1.#IND00
The required solution does not converge or iterations are insufficient

Add a comment
Know the answer?
Add Answer to:
use C programing to solve the following exercise. Compute a root of the equation 4. (20 points) e-3 cos(x)-o using (a) Bisection Method between 0 and I. (b) Newton Method using an initial guess of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • My San Compare the convergence of the Bisection and Newton Method Solve 1ze - 3 0.Use eps-10 as your tolerance. Use a 0,b 1 for the Bisection Method and zo - 1 as your initial guess for the Newto...

    My San Compare the convergence of the Bisection and Newton Method Solve 1ze - 3 0.Use eps-10 as your tolerance. Use a 0,b 1 for the Bisection Method and zo - 1 as your initial guess for the Newton Metho a Find the solution to the indicated accuracy b. Bisection Method took Newton Method took e. Upload a word ile that has the codes and outpur table ierations and iterations Choose File No fle chosen Points possible: 1 This is...

  • Problem 3: (a) Fine the root for the equation given below using the Bisection and Newton-Raphson ...

    Problem 3: (a) Fine the root for the equation given below using the Bisection and Newton-Raphson Numerical Methods (Assume initial value) using C++Programming anguage or any other programming angua ge: x6+5r5 x*e3 - cos(2x 0.3465) 20 0 Use tolerance 0.0001 (b) Find the first five iterations for both solution methods using hand calculation. Note: Show all work done and add your answers with the homework Show Flow Chart for Bisection and Newton-Raphson Methods for Proramming. Note: Yur amwer Som the...

  • (la) Determine the root of the x – ez* + 5 = 0 using the Newton-Raphson...

    (la) Determine the root of the x – ez* + 5 = 0 using the Newton-Raphson method with equation initial guess of xo = 1. Perform the computation until the percentage error is less than 0.03%. (1b) Employ bisection method to determine the root of the f(x)=x* – 3x + 7 =0) using equation two initial guesses of x; =-2.1 and x;, =-1.8 . Perform three iterations and calculate the approximate relative error for the third iteration. What is the...

  • [20 Marks] Question 2 a) Given f(x)= x - 7x2 +14x-6 i) Show that there is...

    [20 Marks] Question 2 a) Given f(x)= x - 7x2 +14x-6 i) Show that there is a root a in interval [0,1] (1 mark) ii) Find the minimum number of iterations needed by the bisection method to approximate the root, a of f(x) = 0 on [0,1] with accuracy of 2 decimal points. (3 marks) iii) Find the root (a) of f(x)= x - 7x² +14x6 on [0,1] using the bisection method with accuracy of 2 decimal points. (6 marks)...

  • 4) (16 points) The function f(x)= x? – 2x² - 4x+8 has a double root at...

    4) (16 points) The function f(x)= x? – 2x² - 4x+8 has a double root at x = 2. Use a) the standard Newton-Raphson, b) the modified Newton-Raphson to solve for the root at x = 2. Compare the rate of convergence using an initial guess of Xo = 1,2. 5) (14 points) Determine the roots of the following simultaneous nonlinear equations using a) fixed-point iteration and b) the Newton-Raphson method: y=-x? +x+0,75 y + 5xy = r? Employ initial...

  • c++ Newton method for iteratively finding the root f(x) = 0. The equation is Where f(x)...

    c++ Newton method for iteratively finding the root f(x) = 0. The equation is Where f(x) is the function, f'(x) is the derivative of f9x), Write a C++ program to find root for the function of f(x). The function is on your C++ homework 2 for F(x) = x + 2x -10 You may have two functions, for example, float f(float x) float f=x*x-4; //any function equation return f; float prime(float x) float prime = 2 * x; //derivative of...

  • Using the Bisection method, find an approximate root of the equation sin(x)=1/x that lies between x=1...

    Using the Bisection method, find an approximate root of the equation sin(x)=1/x that lies between x=1 and x=1.5 (in radians). Compute upto 5 iterations. Determine the approximate error in each iteration. Give the final answer in a tabular form.

  • Not in C++, only C code please In class, we have studied the bisection method for...

    Not in C++, only C code please In class, we have studied the bisection method for finding a root of an equation. Another method for finding a root, Newton's method, usually converges to a solution even faster than the bisection method, if it converges at all. Newton's method starts with an initial guess for a root, xo, and then generates successive approximate roots X1, X2, .... Xj, Xj+1, .... using the iterative formula: f(x;) X;+1 = x; - f'(x;) Where...

  • Using MATLAB or FreeMat ---------------------------- Bisection Method and Accuracy of Rootfinding Consider the function f(0) =...

    Using MATLAB or FreeMat ---------------------------- Bisection Method and Accuracy of Rootfinding Consider the function f(0) = 3 cos 2r cos 4-2 cos Garcos 3r - 6 cos 2r sin 2r-5.03r +5/2. This function has exactly one root in the interval <I<1. Your assignment is to find this root accurately to 10 decimal places, if possible. Use MATLAB, which does all calculations in double precision, equivalent to about 16 decimal digits. You should use the Bisection Method as described below to...

  • 3 Newton and Secant Method [30 pts]. We want to solve the equation f(x) 0, where f(x) = (x-1 )4. ...

    Can you help me with parts A to D please? Thanks 3 Newton and Secant Method [30 pts]. We want to solve the equation f(x) 0, where f(x) = (x-1 )4. a) Write down Newton's iteration for solving f(x) 0. b) For the starting value xo 2, compute x c) What is the root ξ of f, i.e., f(5) = 0? Do you expect linear or quadratic order of convergence to 5 and why? d) Name one advantage of Newton's...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT