Question
**Write In JAVA Please!!**
2. Write a program to apply the Modified Newtons Method Tn-1 to the equation ()3r2 +4 0 starting with o 3. Use m and 2 and make separate numerical runs. In each case, set the maximum number of iterations to 25, but stop the computation when the backward error, i.e. f(n), is less than 10-12, Print all intermediate points xn and backward errors f(xn). Verify the convergence rates of your numerical solutions in both cases. (For m 1, you should observe linear convergence. For m-2, you should get quadratic convergence.) Use double precision in your computation. 15 points)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Newton_method {
static double f(double x)
{
return x*x*x-3*x*x+4;
}
static double f_d(double x)
{ return 3*x*x-6*x;
}
public static void main(String args[])
{
int max_ite=25;
double x0=3;
int m=1;
double xn=x0;
System.out.println("When x0=3 amd m=1");
for( int i=1;i<=max_ite;i++)
{double error=Newton_method.f(xn);
xn=xn-(m*Newton_method.f(xn)/Newton_method.f_d(xn));
System.out.println("x"+i+"="+xn+" backward error="+error);
if(Newton_method.f(xn)<Math.pow(10,-12))
break;
}

m=2;
xn=x0;
System.out.println("When x0=3 amd m=2");
for( int i=1;i<=max_ite;i++)
{
double error=Newton_method.f(xn);
xn=xn-(m*Newton_method.f(xn)/Newton_method.f_d(xn));
System.out.println("x"+i+"="+xn+" backward error="+error);
if(Newton_method.f(xn)<Math.pow(10,-12))
break;
}
}
}

02 1緊 -4).ill 2:44 PM codechef - NetBeans IDE 8.1 File Edit View Navigate Source Refactor Run Debug Profile Team Tools Window Heljp Search (Ctri+) <defoult config> Projects Files Services validate datejava X d Distinct valuesjeva x nary search java x a Hex2Decija a X d wheel java PowersOf.java × a Newton method java x ^ | Source History @鳳, 1-1 a | ip b % 쉘 쉴 | ๑目叁 break; MaxMn_Woutsort.java Midter.java 23 24 25 26 -E MultpicationTable java MyArray Class.java MyClass.java Output codechef (run)x MyRectangle.java MyStore.java My.conw.jaa x4-2.079562210414363 backward error-0.07619041150159767 x5-2.04028843517102 backward error-0.019494076332438937 x6-2.0202768097867394 backward error-0.004934868521786484 x7-2.0101723234314033 backward error-0.001241783835759236 x8-2.0050947410932642 backward error-3.1148108498690874E-4 x9-2.002549528082828 backward error-7.300140149250012E-5 x10-2.0012753050263874 backward error-1.951685250389800BE-5 x11-2.000637787960171 backward error-4.881282892554BSE-6 x12-2.0003189278668465 backward error-1.2205798824993502E-6 x13-2.0001594724082197 Dackward error-3.0517739268987043E-7 x14-2.0000797383254 backward error-7.629840048650749E-8 x15-2.0000398696943877 backward crror-1.907510771559373E-8 x16-2.0000199349781793 backward error-4.768841321833861E-9 x17 2.0000099675379546 Dackward error-1.1922161036181933E-9 x18-2.000004983802586 backward error-2.98054914082968E-10 x19-2.0000024919157946 backward crror-7.451461669916171E-11 x20 2.000001245978097 backward error-1.86286541747904272-11 x21-2.000000622721945 Dackward error-4. 6593B3989746857E-12 x22-2.0000003113166764 backward error-1.1635137298071642-12 When x0-3 amd m-2 Myclass1.java NegativeOrPos tive.java Members Newton method x2-2.001949317738795 backward exror-0.03840877914951868 x3-2.0000006326900053 Dackward error-1.14069260348514942-5 x4-2.0000000000385048 backward error-1.2008172234345693E-12 BUILD SUCCESSFUL (total time: 0 seconds) Activate Windows Go to PC settings to activate Windows 27:45 INS

Add a comment
Know the answer?
Add Answer to:
**Write In JAVA Please!!** 2. Write a program to apply the Modified Newton's Method Tn-1 to...
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
  • Problem 1 (Matlab): One of the most fundamental root finding algorithms is Newton's Method. Given a real-valued, di...

    Problem 1 (Matlab): One of the most fundamental root finding algorithms is Newton's Method. Given a real-valued, differentiable function f, Newton's method is given by 1. Initialization: Pick a point xo which is near the root of f Iteratively define points rn+1 for n = 0,1,2,..., by 2. Iteration: f(xn) nt1 In 3. Termination: Stop when some stopping criterion occurs said in the literature). For the purposes of this problem, the stopping criterion will be 100 iterations (This sounds vague,...

  • this is numerical analysis. please do a and b 1. This problem is concerned with solving...

    this is numerical analysis. please do a and b 1. This problem is concerned with solving the equation f(x) = 0 using Newton's method, assuming f is a smooth (Cº) function. (a) Write the iteration representing Newton's method for solving f(x) = 0 and briefly state under what conditions the iteration makes sense, (b) Write Newton's method for solving the equation x"" = 0, where m > 2 is an integer. Show that the convergence is linear, not quadratic, and...

  • 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...

  • Page 73, as mentioned in the stated question, is provided below 1. Consider a new root-finding...

    Page 73, as mentioned in the stated question, is provided below 1. Consider a new root-finding method for solving f(x) = 0. Successive guesses for the root are generated from the following recurrence formula: Xn+1 = In f(xn) fhen + f(xn)] – F(Xn) (1) Write a user-defined function with the function call: [r, n] = Root fun (f, xl, tol, N) The inputs and outputs are the same as for the user-defined function Newton described on page 73 of Methods....

  • Write a Java program that uses the Monte Carlo method to estimate the value of PI....

    Write a Java program that uses the Monte Carlo method to estimate the value of PI. This method uses the unit circle inscribed in a square with sides of length 2 and random numbers to perform the estimation. The estimation works as follows: • Two random numbers are generated during each iteration of a loop. • The random numbers are each in the range of -1 to 1. One random number is the x-coordinate and the other is the y-coordinate....

  • 1) (80pts) Consider the following function f(x)--x5-4x4 + 2x3 + x2-3x + 5 Develop a simple program which will give an iterative solution to the problem f(x)=0 by Newton's algorithm. The solut...

    1) (80pts) Consider the following function f(x)--x5-4x4 + 2x3 + x2-3x + 5 Develop a simple program which will give an iterative solution to the problem f(x)=0 by Newton's algorithm. The solution should display the results on an Excel spreadsheet such as the one given below (the example below is given for a different function). Choose the programming language which suits you most, however the program should be able to read data from an Excel spreadsheet and write the successive...

  • Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order,...

    Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order, and to plot a binary tree into a 2-dimensional array. You may write many recursive methods for this project. You are not allowed to use any existing Java classes such as ArrayList or Vector or Tree. Please stop your program if the user enters 0 as the tree selection. Your program must run the following Test Case 1 plus two more test cases to...

  • You will write a C program, q1 sequence.c, that computes the value of the nth term...

    You will write a C program, q1 sequence.c, that computes the value of the nth term in any recursive sequence with the following structure: an = c1 · an−1 + c2 · an−2 a0 > 0 a1 > 0 c1 6= 0 c2 6= 0 Your C program will take 5 integer arguments on the command line: n, a0, a1, c1 and c2. n must be an integer greater than or equal to 0. If more or fewer arguments are...

  • Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order, and to plot a binar...

    Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order, and to plot a binary tree into a 2-dimensional array. You may write many recursive methods for this project. You are not allowed to use any existing Java classes such as ArrayList or Vector or Tree. Please stop your program if the user enters 0 as the tree selection. Your program must run the following Test Case 1 plus two more test cases to...

  • Note: According to the question, please write source code in java only using the class method....

    Note: According to the question, please write source code in java only using the class method. Sample Run (output) should be the same as displayed in the question below. Make sure the source code is working properly and no errors. Exercise #2: Design and implement a program (name it compareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array...

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