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;
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
add a comment |
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
Where did you get thatepsilon*t
from? What does this document/article wrote about this expression and why the factor*t
is used?
– Progman
Mar 27 at 18:58
add a comment |
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
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
java newtons-method
asked Mar 27 at 16:42
Tr909Tr909
91 bronze badge
91 bronze badge
Where did you get thatepsilon*t
from? What does this document/article wrote about this expression and why the factor*t
is used?
– Progman
Mar 27 at 18:58
add a comment |
Where did you get thatepsilon*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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 27 at 18:57
ProgmanProgman
7,2573 gold badges21 silver badges37 bronze badges
7,2573 gold badges21 silver badges37 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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