Advertisement
Guest User

111

a guest
Apr 19th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.46 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.RandomAccessFile;
  3. import java.util.Locale;
  4.  
  5. public class Main {
  6.  
  7.     private static void printResult(double tau_1, double tau_2, double x_2, int param, RandomAccessFile common) throws IOException {
  8.         double temp;
  9.         if (tau_1 > 0) {
  10.             temp = (x_2 * (param * tau_1 + 1) + 5 * param * tau_1) / 10;
  11.             if (temp > 0 && temp < 1) {
  12.                 common.writeInt(param);
  13.                 common.seek(2);
  14.                 common.writeChars(String.format(Locale.US, "%.4f", temp));
  15.                 common.seek(9);
  16.                 common.writeChars(String.format(Locale.US, "%.1f", x_2));
  17.                 common.seek(14);
  18.                 common.writeChars(String.format(Locale.US, "%.4f", tau_1));
  19.                 common.seek(23);
  20.                 common.writeChars(String.format(Locale.US, "%.4f", tau_1));
  21.                 common.seek(33);
  22.                 common.writeChars(String.format(Locale.US, "%.4f", tau_1 * param));
  23.                 common.seek(43);
  24.                 common.writeChars("\n");
  25.             }
  26.         }
  27.         if (tau_2 > 0) {
  28.             temp = (x_2 * (param * tau_2 + 1) + 5 * param * tau_2) / 10;
  29.             if (temp > 0 && temp < 1) {
  30.                 common.writeInt(param);
  31.                 common.seek(2);
  32.                 common.writeChars(String.format(Locale.US, "%.4f", temp));
  33.                 common.seek(9);
  34.                 common.writeChars(String.format(Locale.US, "%.1f", x_2));
  35.                 common.seek(14);
  36.                 common.writeChars(String.format(Locale.US, "%.4f", tau_2));
  37.                 common.seek(23);
  38.                 common.writeChars(String.format(Locale.US, "%.4f", tau_2));
  39.                 common.seek(33);
  40.                 common.writeChars(String.format(Locale.US, "%.4f", tau_2 * param));
  41.                 common.seek(43);
  42.                 common.writeChars("\n");
  43.             }
  44.         }
  45.     }
  46.  
  47.     public static void main(String[] args) throws IOException {
  48.         RandomAccessFile common = new RandomAccessFile("common.txt", "rw");
  49.         common.writeChars("A  X1     X2   TAU      P2        P5       \n");
  50.         int[] param = {1, 2, 4};
  51.         double a, b, c, x_2, tau_1, tau_2;
  52.         for (int i = 0; i < 3; i++)
  53.             for (int j = 0; j < 151; j++) {
  54.                 x_2 = -5.0 + j * 0.1;
  55.                 a = param[i] * (x_2 + 5) * Math.pow(Math.E, (x_2 / (1 + x_2 / 20))) / -10;
  56.                 b = param[i] * (x_2 + 5) / -10 + Math.pow(Math.E, (x_2 / (1 + x_2 / 20))) + x_2 * Math.pow(Math.E, (x_2 / (1 + x_2 / 20))) / -10;
  57.                 c = x_2 / -10;
  58.                 if (Math.pow(b, 2) - 4 * a * c <= 0)
  59.                     System.out.println("Корни отсутствуют при a= " + param[i] + ", x_2= " + String.format(Locale.US, "%.1f", x_2));
  60.                 else if (Math.pow(b, 2) - 4 * a * c > 0) {
  61.                     tau_1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
  62.                     tau_2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
  63.                     System.out.println("Корни квадратного уравнения при a= " + param[i] + ", x_2= "
  64.                             + String.format(Locale.US, "%.1f", x_2) + ". tau_1 = " + String.format(Locale.US, "%.4f", tau_1) + " tau_2 = " + String.format(Locale.US, "%.4f", tau_2));
  65.                     printResult(tau_1, tau_2, x_2, param[i], common);
  66.                 }
  67.             }
  68.         common.close();
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement