SHARE
TWEET

Untitled

a guest Oct 21st, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.OutputStream;
  2. import java.io.PrintWriter;
  3. import java.util.Scanner;
  4.  
  5. public class false_position_M {
  6.     public static void main(String[] args) {
  7.         Scanner in = new Scanner(System.in);
  8.         OutputStream outputStream =  System.out;
  9.         PrintWriter out = new PrintWriter(outputStream);
  10.  
  11.  
  12.         double xl = 3, xu = 4, xr,f_xu, f_xl, f_xr,a,b,c,Ea,previous_xr;
  13.         f_xu = function_method(xu);
  14.         f_xl = function_method(xl);
  15.         xr = xu - ((f_xu * (xl - xu)) / (f_xl - f_xu));
  16.         f_xr = function_method(xr);
  17.         previous_xr = xr;
  18.  
  19.         if ( (f_xr * f_xl) > 0){
  20.             xl = xr ;
  21.             f_xu = function_method(xu);
  22.             f_xl = function_method(xl);
  23.             xr = xu - ((f_xu * (xl - xu)) / (f_xl - f_xu));
  24.             f_xr = function_method(xr);
  25.             Ea =(( xr - previous_xr ) / xr ) * 100;
  26.             previous_xr = xr;
  27.         }
  28.         else {
  29.             xu = xr ;
  30.             f_xu = function_method(xu);
  31.             f_xl = function_method(xl);
  32.             xr = xu - ((f_xu * (xl - xu)) / (f_xl - f_xu));
  33.             f_xr = function_method(xr);
  34.             Ea =(( xr - previous_xr ) / xr ) * 100;
  35.             previous_xr = xr;
  36.         }
  37.  
  38.         if (Ea < 0) Ea *= -1;
  39.         int i = 0;
  40.  
  41.         while (Ea > 5)
  42.         {
  43.             i++;
  44.             if ( (f_xr * f_xl) > 0){
  45.                 xl = xr ;
  46.                 f_xu = function_method(xu);
  47.                 f_xl = function_method(xl);
  48.                 xr = xu - ((f_xu * (xl - xu)) / (f_xl - f_xu));
  49.                 f_xr = function_method(xr);
  50.                 Ea =(( xr - previous_xr ) / xr ) * 100;
  51.                 previous_xr = xr;
  52.             }
  53.             else {
  54.                 xu = xr ;
  55.                 f_xu = function_method(xu);
  56.                 f_xl = function_method(xl);
  57.                 xr = xu - ((f_xu * (xl - xu)) / (f_xl - f_xu));
  58.                 f_xr = function_method(xr);
  59.                 Ea =(( xr - previous_xr ) / xr ) * 100;
  60.                 previous_xr = xr;
  61.             }
  62.  
  63.             if (Ea < 0) Ea *= -1;
  64.         }
  65.  
  66.         out.println(Ea + " " + i);
  67.  
  68.         out.flush();
  69.  
  70.  
  71.     }
  72.  
  73.  
  74.     public static double function_method(double x){
  75.         double sin = Math.sin(Math.toRadians(x));
  76.         double cos = Math.cos(Math.toRadians(x));
  77.         double ex = Math.expm1(-x);
  78.         return (ex*((3.2*sin) - 0.5*cos));
  79.         //return  ex;
  80.     }
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top