Cubic Root by Newton's Iterative Method

This is a discussion on Cubic Root by Newton's Iterative Method within the C++ Programming forums, part of the General Programming Boards category; Hi there, I have this exercise which I understand except a very small part at the end which is "for ...

  1. #1
    Amy amirahasanen1's Avatar
    Join Date
    Jul 2003
    Posts
    49

    Question Cubic Root by Newton's Iterative Method

    Hi there,
    I have this exercise which I understand except a very small part at the end which is "for each x use e = 0.1 , 0.001, 0.00001."
    Here am I required to get three cubic root values for each x and return the three values by the cubic-root function and then compare them with that value returned by the C++ normal power function??? If it is like that it seems a little bit confusing to me as why are we going to use three values for the tolerance..
    Thanks,


    -Amy




    Exercise:
    The cubic root x^(1/3) of a real number x can be computed using an iterative method called Newton’s Method. In this method we start with an initial guess Y for the cubic root, and then iteratively compute better approximations using the formula:
    Ynew = Y – [Y * Y – x / Y] / [ 2 Y + x / (Y * Y)]

    In a given iteration, if the absolute relative difference between Ynew and Y is greater than a certain tolerance e, i.e. if | Ynew - Y | / Y > e , we repeat computing a better value Ynewotherwise we stop.

    Write a function to input the real number x and the tolerance (e) and to return the cubic root of x using an initial guess of Y = x. The function should also return the number of iterations needed to achieve the final value of the cubic root.

    Use a main function to test the above function by comparing its cubic root with that computed using the usual C++ power function. Choose x = 0.01 , 0.1 , 1 , 10 , 100 and for each x use e = 0.1 , 0.001, 0.00001. Also, display the number of iterations needed in each case.
    Last edited by amirahasanen1; 03-15-2005 at 01:21 PM.
    It ain't illegal until you get caught..

  2. #2
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    It sounds like just an exercise that will help you see how things work. In the end, you will have three values for the cube root that you generated, and one value for the cube root that the c++ power function generates. From this, you will get an idea of what value of e your c++ implementation uses for it's power function. You will also see how accurate (or inaccurate) certain values of e are.

    Does this answer your question, or are you looking for something more specific? I think I probably shouldn't post code, since this is for school, but maybe if you post what code you have, I can give more suggestions.
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  3. #3
    Amy amirahasanen1's Avatar
    Join Date
    Jul 2003
    Posts
    49

    Smile

    Yes, you should not post code I just wanted to understand what the exercise itself requires me to do for now so that I start working on the code, but then if I faced problems with my code I'd post it here.
    So now I will get three values for cubic root of x using different e's and then compare them to that one using C++ power function.
    Thank you,

    -Amy
    It ain't illegal until you get caught..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer confusion
    By Blackroot in forum C++ Programming
    Replies: 11
    Last Post: 09-12-2007, 01:44 AM
  2. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  3. Newton's method
    By Cmuppet in forum C Programming
    Replies: 5
    Last Post: 10-19-2004, 12:02 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  5. Templated Binary Tree... dear god...
    By Nakeerb in forum C++ Programming
    Replies: 15
    Last Post: 01-17-2003, 02:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21