Interpretable code using Newton-Raphson MethodHow to avoid Java code in JSP files?Newton Raphsons method in Matlab?Why does this code using random strings print “hello world”?Newton-Raphson method in MathematicaHow to use Newton-Raphson method to find the square root of a BigInteger in C#Newton-Raphson Method in MatlabNewton-Raphson Method in JavaDivision by zero in the Newton-Raphson methodWhy is executing Java code in comments with certain Unicode characters allowed?Newton Raphson in Java code for beginners

Non-visual Computers - thoughts?

LeetCode: Pascal's Triangle C#

Which household object drew this pattern?

What is the best option for High availability on a data warehouse?

I have a player who yells

Is it possible to get crispy, crunchy carrots from canned carrots?

Cross-referencing enumerate item

Numbers Decrease while Letters Increase

Why does trim() NOT remove char 160?

Can I double-dip a flight and claim it for both United and Lufthansa status miles?

Sun setting in East!

Is a player able to change alignment midway through an adventure?

Avoiding racist tropes in fantasy

Is “I am getting married with my sister” ambiguous?

Using `With[...]` with a list specification as a variable

Most practical knots for hitching a line to an object while keeping the bitter end as tight as possible, without sag?

What is wrong about this application of Kirchhoffs Current Law?

Justifying the use of directed energy weapons

If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?

Why is my Earth simulation slower than the reality?

Please help me identify the bold slashes between staves

What is the hex versus octal timeline?

Compelling story with the world as a villain

Rule based coloured background for labeling in QGIS



Interpretable code using Newton-Raphson Method


How to avoid Java code in JSP files?Newton Raphsons method in Matlab?Why does this code using random strings print “hello world”?Newton-Raphson method in MathematicaHow to use Newton-Raphson method to find the square root of a BigInteger in C#Newton-Raphson Method in MatlabNewton-Raphson Method in JavaDivision by zero in the Newton-Raphson methodWhy is executing Java code in comments with certain Unicode characters allowed?Newton Raphson in Java code for beginners






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am having troubles with a Java code that must calculate the root square of a given parameter.
However,after some research I found a code that I don't know how was implemented properly.



 // read in the command-line argument
double c = Double.parseDouble(args[0]);
double epsilon = 1.0e-15; // relative error tolerance
double t = c; // estimate of the square root of c

// repeatedly apply Newton update step until desired precision is achieved
while (Math.abs(t - c/t) > epsilon *t)
t = (c/t + t) / 2.0;


// print out the estimate of the square root of c
System.out.println(t);


The first thing that I don't understand completely is why they are dividing by two on the 8th line.



 t = (c/t + t) / 2.0;


The second thing which I do not understand is the condition from the while loop, to be more precise:



 while(Math.abs(t - c/t) > epsilon*t) 


Wouldn't be necessary to have only:



 while(Math.abs(t - c/t) > epsilon) 









share|improve this question
























  • Where did you get that epsilon*t from? What does this document/article wrote about this expression and why the factor *t is used?

    – Progman
    Mar 27 at 18:58

















0















I am having troubles with a Java code that must calculate the root square of a given parameter.
However,after some research I found a code that I don't know how was implemented properly.



 // read in the command-line argument
double c = Double.parseDouble(args[0]);
double epsilon = 1.0e-15; // relative error tolerance
double t = c; // estimate of the square root of c

// repeatedly apply Newton update step until desired precision is achieved
while (Math.abs(t - c/t) > epsilon *t)
t = (c/t + t) / 2.0;


// print out the estimate of the square root of c
System.out.println(t);


The first thing that I don't understand completely is why they are dividing by two on the 8th line.



 t = (c/t + t) / 2.0;


The second thing which I do not understand is the condition from the while loop, to be more precise:



 while(Math.abs(t - c/t) > epsilon*t) 


Wouldn't be necessary to have only:



 while(Math.abs(t - c/t) > epsilon) 









share|improve this question
























  • Where did you get that epsilon*t from? What does this document/article wrote about this expression and why the factor *t is used?

    – Progman
    Mar 27 at 18:58













0












0








0








I am having troubles with a Java code that must calculate the root square of a given parameter.
However,after some research I found a code that I don't know how was implemented properly.



 // read in the command-line argument
double c = Double.parseDouble(args[0]);
double epsilon = 1.0e-15; // relative error tolerance
double t = c; // estimate of the square root of c

// repeatedly apply Newton update step until desired precision is achieved
while (Math.abs(t - c/t) > epsilon *t)
t = (c/t + t) / 2.0;


// print out the estimate of the square root of c
System.out.println(t);


The first thing that I don't understand completely is why they are dividing by two on the 8th line.



 t = (c/t + t) / 2.0;


The second thing which I do not understand is the condition from the while loop, to be more precise:



 while(Math.abs(t - c/t) > epsilon*t) 


Wouldn't be necessary to have only:



 while(Math.abs(t - c/t) > epsilon) 









share|improve this question














I am having troubles with a Java code that must calculate the root square of a given parameter.
However,after some research I found a code that I don't know how was implemented properly.



 // read in the command-line argument
double c = Double.parseDouble(args[0]);
double epsilon = 1.0e-15; // relative error tolerance
double t = c; // estimate of the square root of c

// repeatedly apply Newton update step until desired precision is achieved
while (Math.abs(t - c/t) > epsilon *t)
t = (c/t + t) / 2.0;


// print out the estimate of the square root of c
System.out.println(t);


The first thing that I don't understand completely is why they are dividing by two on the 8th line.



 t = (c/t + t) / 2.0;


The second thing which I do not understand is the condition from the while loop, to be more precise:



 while(Math.abs(t - c/t) > epsilon*t) 


Wouldn't be necessary to have only:



 while(Math.abs(t - c/t) > epsilon) 






java newtons-method






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 16:42









Tr909Tr909

91 bronze badge




91 bronze badge















  • Where did you get that epsilon*t from? What does this document/article wrote about this expression and why the factor *t is used?

    – Progman
    Mar 27 at 18:58

















  • Where did you get that epsilon*t from? What does this document/article wrote about this expression and why the factor *t is used?

    – Progman
    Mar 27 at 18:58
















Where did you get that epsilon*t from? What does this document/article wrote about this expression and why the factor *t is used?

– Progman
Mar 27 at 18:58





Where did you get that epsilon*t from? What does this document/article wrote about this expression and why the factor *t is used?

– Progman
Mar 27 at 18:58












1 Answer
1






active

oldest

votes


















0















t = (c/t + t) / 2.0;


This is used to calculate the average/mean of the two values c/t and t. The value is stored in the variable t for the next loop iteration. Use a System.out.println() call inside the while loop to check the values of t and c/t before this line and the values after this line.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382432%2finterpretable-code-using-newton-raphson-method%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    t = (c/t + t) / 2.0;


    This is used to calculate the average/mean of the two values c/t and t. The value is stored in the variable t for the next loop iteration. Use a System.out.println() call inside the while loop to check the values of t and c/t before this line and the values after this line.






    share|improve this answer





























      0















      t = (c/t + t) / 2.0;


      This is used to calculate the average/mean of the two values c/t and t. The value is stored in the variable t for the next loop iteration. Use a System.out.println() call inside the while loop to check the values of t and c/t before this line and the values after this line.






      share|improve this answer



























        0














        0










        0









        t = (c/t + t) / 2.0;


        This is used to calculate the average/mean of the two values c/t and t. The value is stored in the variable t for the next loop iteration. Use a System.out.println() call inside the while loop to check the values of t and c/t before this line and the values after this line.






        share|improve this answer













        t = (c/t + t) / 2.0;


        This is used to calculate the average/mean of the two values c/t and t. The value is stored in the variable t for the next loop iteration. Use a System.out.println() call inside the while loop to check the values of t and c/t before this line and the values after this line.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 18:57









        ProgmanProgman

        7,2573 gold badges21 silver badges37 bronze badges




        7,2573 gold badges21 silver badges37 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382432%2finterpretable-code-using-newton-raphson-method%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript