Question

Not in C++, only C code pleaseIn class, we have studied the bisection method for finding a root of an equation. Another method for finding a root, NewtonsWrite a program that uses Newtons method to approximate the nth root of a number to six decimal places. If x” = C, then x —

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C code:

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

//  this will find the n th root of a number x
double find_nthRoot(int x, int n){ 
    //count iteration
        int count=0;
        // declare the accuracy
        double accuracy=0.000001;
        
        // intially guess
        double prev = pow(x, n)/2;
    
        // it stores the difference between two roots
    double diff = INT_MAX; 
  
    //  it stores current value of x^n
    double current_x; 
  
    //  repeat until the accuracy achieved
    while (diff > accuracy && count<100){ 
        //  calculating current value using previous 
        current_x = ((n - 1.0) * prev + (double)x/pow(prev, n-1)) / (double)n; 
        diff = current_x - prev;
                // make positive
                if(diff<0)
                        diff=-diff; 
        prev = current_x; 
        count++;
    } 
    return current_x; 
} 
  
// Driver code
int main(){ 
    // declare variables
        int x, n;
        double result;
        
        //take input
        printf("Enter the value of x in nthtroot(x): ");
        scanf("%d",&x);
        printf("Enter the value of n in nthtroot(x): ");
        scanf("%d",&n);
    
    // call the function
        result = find_nthRoot(x, n); 
        
        //display the result
    printf("%d root of %d is %lf",n,x,result); 
  
    return 0; 
}

___________________________________________________________________

Output:

Case 1:

Enter the value of x in nthtroot(x): 3
Enter the value of n in nthtroot(x): 2
2 root of 3 is 1.732051

Case 2:

Enter the value of x in nthtroot(x): 3
Enter the value of n in nthtroot(x): 10
10 root of 3 is 1.116123


Case 3:

Enter the value of x in nthtroot(x): 2
Enter the value of n in nthtroot(x): 3
3 root of 2 is 1.259921

___________________________________________________________________


Note: If you have queries or confusion regarding this question, please leave a comment. I would be happy to help you. If you find it to be useful, please upvote.

Add a comment
Know the answer?
Add Answer to:
Not in C++, only C code please In class, we have studied the bisection method for...
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
  • Please show the steps to answer this question We consider bisection method for finding the root...

    Please show the steps to answer this question We consider bisection method for finding the root of the function f(x) = 2.3 – 1 on the interval [0, 1], so Xo = 0.5. We perform 2 steps, and our approximations Xi and X2 from these two steps are: O x1 = 1, X2 = 0.6 O x1 = 0.7, x2 = 0.8 O x1 = 0.75, x2 = 0.875 O x1 = 0.3, 22 = 0.6

  • (1) Use the Bisection method to find solutions accurate to within 10-2 for x3 – 7x2...

    (1) Use the Bisection method to find solutions accurate to within 10-2 for x3 – 7x2 + 14x – 6 = 0 on the interval [3.2, 4]. Using 4-digit rounding arithmatic. (2) Consider the function f(x) = cos X – X. (a). Approximate a root of f(x) using Fixed- point method accurate to within 10-2 . (b). Approximate a root of f(x) using Newton's method accurate to within 10-2. Find the second Taylor polynomial P2(x) for the function f(x) =...

  • Newton's Method in MATLAB During this module, we are going to use Newton's method to compute...

    Newton's Method in MATLAB During this module, we are going to use Newton's method to compute the root(s) of the function f(x) = x° + 3x² – 2x – 4 Since we need an initial approximation ('guess') of each root to use in Newton's method, let's plot the function f(x) to see many roots there are, and approximately where they lie. Exercise 1 Use MATLAB to create a plot of the function f(x) that clearly shows the locations of its...

  • Please write in Language c using only the files stdio.h and math.h Suppose you wish to...

    Please write in Language c using only the files stdio.h and math.h Suppose you wish to find the root r of a function f(x), that is, the value r where f(r)=0. One method is to make an initial guess, x0, compute the line tangent to f at x0, and find where the tangent line intercepts the x-axis, x1. Then, use x1 as the second guess and repeat this procedure n times until f(xn) approximately equals 0 and report xn as...

  • Problem 4 (5 pt) Compute a root of the function f(x) = x2-2 using the secant method with initial ...

    Problem 4 (5 pt) Compute a root of the function f(x) = x2-2 using the secant method with initial guess xo - 1.5 and xj 1 Choose a different initial guess and compute another root of the function f(x) Problem 4 (5 pt) Compute a root of the function f(x) = x2-2 using the secant method with initial guess xo - 1.5 and xj 1 Choose a different initial guess and compute another root of the function f(x)

  • LAB 2 APROXIMATING ZEROS OF FUNCTIONS USING NEWTON'S METHOD (Refer to section 3.8 of your textbook...

    LAB 2 APROXIMATING ZEROS OF FUNCTIONS USING NEWTON'S METHOD (Refer to section 3.8 of your textbook for details in the derivation of the method and sample problems) (NOTE: You can use Derive, MicrosoftMathematics or Mathematica or any other Computer Algebra System of your choice. Your final report must be clear and concise. You must also provide sufficient comments on your approach and the final results in a manner that will make your report clear and accessible to anyone who is...

  • This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable...

    This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable to transcribe this imageNewton's Method We have already seen the bisection method, which is an iterative root-finding method. The Newton Rhapson method (Newton's method) is another iterative root-finding method. The method is geometrically motivated and uses the derivative to find roots. It has the advantage that it is very fast (generally faster than bisection) and works on problems with double (repeated) roots, where the...

  • Using newton's method calculate to the first 3 iterations. DO NOT WORRY ABOUT THE CODING OR ANYTHING. IHAVE ALRE...

    Using newton's method calculate to the first 3 iterations. DO NOT WORRY ABOUT THE CODING OR ANYTHING. IHAVE ALREADY COMPLETED THAT. ONLY HAND WRITTEN CALCULATIONS. Foject Goals and Tasks Your goal is to implement Newton's Method in Java for various functions, using a for loop. See the last page of this document for help writing the code. Task 1: (a) Apply Newton's Method to the equation x2 - a = 0 to derive the following square-root algorithm (used by the...

  • Matlab only What is the function value at the estimated root after one iteration of the...

    Matlab only What is the function value at the estimated root after one iteration of the bisection method for the root finding equation: f(x) = x^3 -x -11 with xl = -4 and xu = 2.5? Select one: a.-0.7500 x O b.-3.2500 o co d. -10.6719 Which of the following statements is false? All open methods for root finding: Select one: a. Is sensitive to the shape of the function X b. Require two initial guesses to begin the algorithm...

  • explain why newtons method doesnt work for finding the root of the equation x^3-3x+9=0 if the...

    explain why newtons method doesnt work for finding the root of the equation x^3-3x+9=0 if the initial approximation is chosen to be x1=1 f(x)=x^3-3x+9 -> f'(x)= . if x1=1 then f'(x1)= and the tangent line ued for approximating x2 is . attempting to find x^2 results in trying to by zero 1. [-/100 Points) DETAILS SCALCETS 4.8.031. MY NOTES Explain why Newton's method doesn't work for finding the root of the equation if the initial approximation is chosen to be...

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