{"id":78510,"date":"2021-12-01T13:53:07","date_gmt":"2021-12-01T13:53:07","guid":{"rendered":"https:\/\/papersspot.com\/blog\/2021\/12\/01\/project-compute-roots-using-newton-iteration-objectives-exposure-to-using-double-variables\/"},"modified":"2021-12-01T13:53:07","modified_gmt":"2021-12-01T13:53:07","slug":"project-compute-roots-using-newton-iteration-objectives-exposure-to-using-double-variables","status":"publish","type":"post","link":"https:\/\/papersspot.com\/blog\/2021\/12\/01\/project-compute-roots-using-newton-iteration-objectives-exposure-to-using-double-variables\/","title":{"rendered":"Project: Compute Roots Using Newton Iteration Objectives Exposure to using double variables,"},"content":{"rendered":"<p>Project: Compute Roots Using Newton Iteration<\/p>\n<p> Objectives<\/p>\n<p> Exposure to using\u00a0double\u00a0variables,\u00a0while\u00a0loops, and\u00a0static\u00a0methods<\/p>\n<p> Exposure to using several Eclipse features including creating a project by copying an existing project, renaming a Java file using refactoring, deleting files, creating a file by copying an existing file, using the Java editor, and exporting a project<\/p>\n<p> The Problem<\/p>\n<p> Your first job is to create a Java program that repeatedly asks the user whether they wish to calculate another square root. If the response is &#8220;y&#8221;, then the program should proceed; if it is anything else, then the program should quit. Whenever it proceeds, the program should prompt the user for a number (a positive\u00a0double, and your program may simply assume the input is consistent with this requirement) and then report the square root of that number to within a relative error of no more than 0.01%. The computation must be done using\u00a0Newton iteration.<\/p>\n<p> The intuitive idea of Newton iteration for computing square roots is fairly straightforward. Suppose you have a guess\u00a0r\u00a0for\u00a0x1\/2\u00a0that is too large; the argument is similar if it is too small. If\u00a0r\u00a0is too large to be the square root of\u00a0x, then\u00a0x\/r\u00a0must be too small, so the average of\u00a0r\u00a0and\u00a0x\/r\u00a0should be a better guess than either\u00a0r\u00a0or\u00a0x\/r. This suggests that if you repeatedly replace your current guess\u00a0r\u00a0by\u00a0(r + x\/r)\/2, then your sequence of guesses should converge to\u00a0x1\/2. And indeed it can be proved that it does. A good initial guess for\u00a0x1\/2\u00a0is simply\u00a0r = x. If you continue updating\u00a0r\u00a0until |r2\u00a0\u2013 x\u00a0|\/x &lt; \u03b52, then the relative error of the guess\u00a0r\u00a0will be less than\u00a0\u03b5.<\/p>\n<p> After your initial program works, there are a number of other requirements to change it slightly, one step at a time, as explained below.<\/p>\n<p> Method<\/p>\n<p> Create a new Eclipse project by copying\u00a0ProjectTemplate\u00a0.Name the new project\u00a0Newton.<\/p>\n<p> Open the\u00a0src\u00a0folder of this project and then open\u00a0(default package). As a starting point you should use\u00a0ProgramWithIOAndStaticMethod.java. Rename it\u00a0Newton1\u00a0and delete the other files from the project.<\/p>\n<p> Edit\u00a0Newton1.java\u00a0to satisfy the problem requirements stated above, including updating comments appropriately. Estimating the square root should be done in a static method declared as follows:<\/p>\n<p> Copy\u00a0Newton1.java\u00a0to create\u00a0Newton2.java. Change\u00a0sqrt\u00a0(including its Javadoc comments) so it also works when\u00a0x = 0. Note: if your code from\u00a0Newton1\u00a0appears to work without any changes, but it is such that it might execute a division by 0, then it is not correct. Division by 0, in general, is undefined and you should not write code that attempts to compute it.<\/p>\n<p> Copy\u00a0Newton2.java\u00a0to create\u00a0Newton3.java. Change it so the main program prompts the user to input the value of\u00a0\u03b5\u00a0(rather than assuming it is 0.0001), just once as the program begins, and so this value is also passed to\u00a0sqrt.<\/p>\n<p> Copy\u00a0Newton3.java\u00a0to create\u00a0Newton4.java. Change it so the main program does not ask the user whether they wish to calculate another square root, but instead simply asks for a new value of\u00a0x\u00a0and interprets a negative value as an indication that it&#8217;s time to quit.<\/p>\n<p> Select your Eclipse project\u00a0Newton\u00a0(not just some of the files, but the whole project), create a zip archive of it, and submit the zip archive.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Project: Compute Roots Using Newton Iteration Objectives Exposure to using\u00a0double\u00a0variables,\u00a0while\u00a0loops, and\u00a0static\u00a0methods Exposure to using several Eclipse features including creating a project by copying an existing project, renaming a Java file using refactoring, deleting files, creating a file by copying an existing file, using the Java editor, and exporting a project The Problem Your first job [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10],"class_list":["post-78510","post","type-post","status-publish","format-standard","hentry","category-research-paper-writing","tag-writing"],"_links":{"self":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/78510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/comments?post=78510"}],"version-history":[{"count":0,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/78510\/revisions"}],"wp:attachment":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/media?parent=78510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/categories?post=78510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/tags?post=78510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}