Question

JAVA programming:

Construct a computer program that uses the Secant Method to solve the problem: fox)cos(3.0)- 1.0/20.00 Starting with the initial guesses of x 2 and x- 3, obtain an approximation to x such that fx)<0.000000001. On your output, show the iteration number (n), the approximate value of x on the nth iteration (xn), and the value of fxn Show the values to 9 or 10 digits. -0.5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for your question


public class secant_method {
  
public static double Function(double x) {
return Math.cos((x*x)/3.0) - (1.0/20.0);
}
  

public static void main(String[] args) {
  
  
double x1, x0,x2,x3, precision,check;
int iter=0;
precision = 0.000000001;
x0 = 2;
x1 = 3;
if (Function(x0) Function(x1) < 0)
{
do {

//Intermediate value
x2 = (x0 Function(x1) - x1*Function(x0))/(Function(x1)-Function(x0));
  
  
//Checking is x2 a root
check = Function(x0) Function(x2);
  
// update the value of interval
x0 = x1;
x1 = x2;
  
// update number of iteration
iter++;
  
//if check is 0 then we will break the loop because we got
//the root
if (check == 0)
break;
x3 = (x0 Function(x1) - x1*Function(x0))/(Function(x1)-Function(x0));
  
System.out.println("Iteration :" + iter);
System.out.println("Approx value of x :" + x3);
System.out.println("Value of f(x) :"+ Function(x3));
//repeat untill we get to the precision
} while (Math.abs(x3 - x0) >= precision);
  
System.out.println("Root is "+ x1);
  
System.out.println("No of iterations are "+ iter);
}
  
else
System.out.print("Once check the interval");
  

}

}

Screenshots of the work

2 public class secant method f 4Θ public static double Function (double x) { retu rn Math . cos ( ( x#x ) /3 . θ ) ( 1·0/29·0) ; - 6 7 8 9 public static void main(String[ args) f 12 13 double x1, x0, x2, x3, precision, check; int iter0; precision = Θ.ΘΘΘΘΘΘΘ01; 15 16 XI- if (Function (x8) Function ( x1 ) < θ) * 18 19 20 21 0 //Intermediate value x2 = (x8 * Function ( x1) -x1*Function (x8) ) / ( Function ( x1)-Function (x8) 23 24 25 26 27 28 29 30 31 32 //Checking is x2 a root check = Function (x8) * Function (x2); // update the value of interval x0x1; x1 x2 ; /I update number of iteration28 29 // update the value ot interval 31 32 // update number of iteration iter++ 34 35 36 37 38 39 40 41 //if check is θ then

Add a comment
Know the answer?
Add Answer to:
JAVA programming: Construct a computer program that uses the Secant Method to solve the problem: fox)cos(3.0)-...
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
  • Design and construct a computer program in Java. The following is a plot of the function...

    Design and construct a computer program in Java. The following is a plot of the function f(x) = sin(x3) + x2 : In order to illustrate the effects of the two major error sources, rounding and truncation, attempt to determine an approximation to the derivative of f(x) at x = 2.0 radians using the difference approximation given below. (The true answer is 4 + 12 cos(8) or about 2.2539995942966376896). Use the formula: f'(x) ≃ (f(x+h) - f(x)) / h with...

  • Problem: Write a computer program to implement the Fourth Order Runge-Kutta method to solve the differential...

    Problem: Write a computer program to implement the Fourth Order Runge-Kutta method to solve the differential equation x=x2 (1) cos(x(1))-4fx(t), x(0)=-0.5 Use h-0.01. Evaluate and print a table of the solution over the interval [O, 1 x(t) 0

  • Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as...

    Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as a Constraint Satisfaction Problem, with the following guidelines: 1. Since 3 x 3 puzzles are too trivial for a computer, your program should use 4 x 4 puzzles (also known as Super Sudoku puzzles; see Figure 2 for an example). 2. The program should read a Sudoku puzzle from a text file. The user should be able to browse the file system to select...

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