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