daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Feb 17th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2.  
  3. public class Comparing {
  4.     private static double g = 9.81;
  5.     private static double h = 0.01;
  6.     private static double c = 0.15;
  7.     private static double air_denisty = 1.29;
  8.  
  9.     public static void main(String[] args) {
  10.         double initial_speed = 60;
  11.         double angle = 50;
  12.  
  13.         System.out.println(Galileo(angle, initial_speed));
  14.         System.out.println(Newton(angle, initial_speed, 0.1, 11340, true));
  15.     }
  16.  
  17.     public static double Galileo(double angle, double initial_speed) {
  18.         double radians = Math.toRadians(angle);
  19.         double t = 0;
  20.         double x = 0;
  21.         double y = 0;
  22.         while (y >= 0) {
  23.             t += h;
  24.             x = initial_speed * Math.cos(radians) * t;
  25.             y = initial_speed * Math.sin(radians) * t - g * t * t / 2 ;
  26.             System.out.printf("%.2f;  %.10f;%n", x, y);
  27.         }
  28.         return 2 * Math.tan(radians) * initial_speed * initial_speed * Math.cos(radians) * Math.cos(radians) / g;
  29.     }
  30.  
  31.     public static double Newton(double angle, double initial_speed, double radius, double density, boolean resistance) {
  32.         ArrayList<Double> k1 = new ArrayList<>();
  33.         ArrayList<Double> k2 = new ArrayList<>();
  34.         ArrayList<Double> k3 = new ArrayList<>();
  35.         ArrayList<Double> k4 = new ArrayList<>();
  36.  
  37.         double beta;
  38.  
  39.         if (resistance) {
  40.             beta = c * air_denisty * Math.PI * radius * radius / 2;
  41.         } else beta = 0;
  42.  
  43.         double radians = Math.toRadians(angle);
  44.         double weight = 4 * Math.PI * radius * radius * radius * density / 3;
  45.  
  46.         double initial_u = initial_speed * Math.cos(radians); // скорость по x
  47.         double initial_w = initial_speed * Math.sin(radians); // скорость по у
  48.  
  49.         double x = 0;
  50.         double y = 0;
  51.  
  52.         double x1 = 0;
  53.         double y1 = 0;
  54.  
  55.         while (y >= 0) {
  56.             k1.add(func_x(weight, beta, initial_u, initial_w));
  57.             k1.add(func_y(weight, beta, initial_u, initial_w));
  58.  
  59.             k2.add(func_x(weight, beta, initial_u + k1.get(0) / 2, initial_w + k1.get(1) / 2));
  60.             k2.add(func_y(weight, beta, initial_u + k1.get(0) / 2, initial_w + k1.get(1) / 2));
  61.  
  62.             k3.add(func_x(weight, beta, initial_u + k2.get(0) / 2, initial_w + k2.get(1) / 2));
  63.             k3.add(func_y(weight, beta, initial_u + k2.get(0) / 2, initial_w + k2.get(1) / 2));
  64.  
  65.             k4.add(func_x(weight, beta, initial_u + k3.get(0) , initial_w + k3.get(1) ));
  66.             k4.add(func_y(weight, beta, initial_u + k3.get(0) , initial_w + k3.get(1) ));
  67.  
  68.             initial_u += (k1.get(0) + 2 * k2.get(0) + 2 * k3.get(0) + k4.get(0)) / 6;
  69.             initial_w += (k1.get(1) + 2 * k2.get(1) + 2 * k3.get(1) + k4.get(1)) / 6;
  70.  
  71.             x1 = x;
  72.             y1 = y;
  73.  
  74.             x += initial_u * h;
  75.             y += initial_w * h;
  76.  
  77.             //System.out.printf("%.2f;  %.2f;%n", x, y);
  78.         }
  79.  
  80.         interpolation(y1, y, x1, x);
  81.         return x;
  82.     }
  83.  
  84.     public static double func_x(double weight, double beta, double initial_u, double initial_w) {
  85.         return h * ((-beta) * initial_u * Math.sqrt(initial_u * initial_u + initial_w * initial_w) / weight);
  86.     }
  87.  
  88.     public static double func_y(double weight, double beta, double initial_u, double initial_w) {
  89.         return h * ((-beta * initial_w * Math.sqrt(initial_u * initial_u + initial_w * initial_w) / weight) - g);
  90.     }
  91.  
  92.     private static double interpolation(double y1, double y2, double x1, double x2) {
  93.         return y1 + (y2 - y1)/(x2 - x1) * (0.0 - x1);
  94.     }
  95. }
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
 
Top