Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.Random;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws FileNotFoundException {
- StringBuilder bufor = new StringBuilder("Raport z badania\n");
- System.out.println("Podaj tryb: ");
- Scanner input = new Scanner(System.in);
- int m = input.nextInt();
- System.out.println("Podaj parametr 1:");
- double input0 = input.nextDouble();
- System.out.println("Podaj parametr 2:");
- double input1 = input.nextDouble();
- System.out.println("Podaj parametr 3:");
- double input2 = input.nextDouble();
- double[] inputMatrix = new double[] {input0, input1, input2};
- double[][] w = {
- {0,-1,-3},
- {-1,0,2},
- {-3,2,0}};
- synchronizedMode(bufor, w, inputMatrix);
- }
- private static void synchronizedMode(StringBuilder bufor, double[][] w, double[] v0) throws FileNotFoundException {
- Matrix matrixW = new Matrix(w);
- Matrix matrixV0 = new Matrix(v0);
- Matrix matrixVT, matrixVTm1, matrixUT;
- int step = 0;
- boolean stopCondition = true;
- double energyOld = 0;
- System.out.println(String.format("Macierz wag:\n%s", matrixW.ToString("%.1f", "\t", "\n")));
- System.out.println(String.format("Badanie wektora V0:\n%s", matrixV0.ToString("%.1f", "\t", "\n")));
- bufor.append(String.format("Macierz wag:\n%s\n", matrixW.ToString("%.1f", "\t", "\n")));
- bufor.append(String.format("Badanie wektora V0:\n%s\n", matrixV0.ToString("%.1f", "\t", "\n")));
- matrixV0 = Matrix.Transpose(matrixV0);
- //matrixVTm1 = new Matrix(matrixV0.ToArray(), true);
- while (true) {
- step++;
- System.out.println(String.format("Krok nr %d-------------", step));
- bufor.append(String.format("Krok nr %d-------------\n", step));
- matrixUT = Matrix.Multiply(matrixW, matrixV0);
- System.out.println(String.format("Potencjał wejściowy U(%d):\n%s", step, matrixUT.ToString("%.1f", "\t", "\n")));
- bufor.append(String.format("Potencjał wejściowy U(%d):\n%s\n", step, matrixUT.ToString("%.1f", "\t", "\n")));
- matrixVT = new Matrix(matrixUT.ToBiPolar().ToArray(), true);
- System.out.println(String.format("Potencjał wyjściowy V(%d):\n%s", step, matrixVT.ToString("%.1f", "\t", "\n")));
- bufor.append(String.format("Potencjał wyjściowy V(%d):\n%s\n", step, matrixVT.ToString("%.1f", "\t", "\n")));
- double energy = 0;
- for (int j = 0; j < 3; j++) {
- for (int i = 0; i < 3; i++) {
- energy += matrixW.GetElement(i, j)
- * matrixV0.GetElement(i, 0)
- * matrixVT.GetElement(j, 0);
- }
- }
- energy *= -1;
- System.out.println(String.format("Energia(%d)=%f\n", step, energy));
- bufor.append(String.format("Energia(%d)=%f\n", step, energy));
- if (step == 3)
- break;
- if (matrixV0.Equals(matrixVT))
- break;
- if (energyOld == energy)
- break;
- energyOld=energy;
- matrixVTm1 = new Matrix(matrixVT.ToArray(), true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement