Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.io.RandomAccessFile;
- import java.util.Locale;
- public class Main {
- private static void printResult(double tau_1, double tau_2, double x_2, int param, RandomAccessFile common) throws IOException {
- double temp;
- if (tau_1 > 0) {
- temp = (x_2 * (param * tau_1 + 1) + 5 * param * tau_1) / 10;
- if (temp > 0 && temp < 1) {
- common.writeInt(param);
- common.seek(2);
- common.writeChars(String.format(Locale.US,"%.4f",temp));
- common.seek(9);
- common.writeChars(String.format(Locale.US,"%.1f",x_2));
- common.seek(14);
- common.writeChars(String.format(Locale.US,"%.4f",tau_1));
- common.seek(23);
- common.writeChars(String.format(Locale.US,"%.4f",tau_1));
- common.seek(33);
- common.writeChars(String.format(Locale.US,"%.4f",tau_1*param));;
- common.seek(43);
- common.writeChars("\n");
- }
- }
- if (tau_2 > 0) {
- temp = (x_2 * (param * tau_2 + 1) + 5 * param * tau_2) / 10;
- if (temp > 0 && temp < 1) {
- common.writeInt(param);
- common.seek(2);
- common.writeChars(String.format(Locale.US,"%.4f",temp));
- common.seek(9);
- common.writeChars(String.format(Locale.US,"%.1f",x_2));
- common.seek(14);
- common.writeChars(String.format(Locale.US,"%.4f",tau_2));
- common.seek(23);
- common.writeChars(String.format(Locale.US,"%.4f",tau_2));
- common.seek(33);
- common.writeChars(String.format(Locale.US,"%.4f",tau_2*param));;
- common.seek(43);
- common.writeChars("\n");
- }
- }
- }
- public static void main(String[] args) throws IOException {
- RandomAccessFile common = new RandomAccessFile("common.txt","rw");
- common.writeChars("A X1 X2 TAU P2 P5 \n");
- int[] param = {1, 2, 4};
- double a, b, c, x_2, tau_1, tau_2;
- for (int i = 0; i < 3; i++)
- for (int j = 0; j < 151; j++) {
- x_2 = -5.0 + j * 0.1;
- a = param[i] * (x_2 + 5) * Math.pow(Math.E, (x_2 / (1 + x_2 / 20))) / -10;
- 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;
- c = x_2 / -10;
- if (Math.pow(b, 2) - 4 * a * c <= 0)
- System.out.println("Корни отсутствуют при a= " + param[i] + ", x_2= " + String.format(Locale.US, "%.1f", x_2));
- else if (Math.pow(b, 2) - 4 * a * c > 0) {
- tau_1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
- tau_2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
- System.out.println("Корни квадратного уравнения при a= " + param[i] + ", x_2= "
- + 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));
- printResult(tau_1, tau_2, x_2, param[i], common);
- }
- }
- common.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement