Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package grafikag;
- import Jama.Matrix;
- import ptolemy.plot.Plot;
- import ptolemy.plot.PlotApplication;
- public class Main {
- public static void mygraph(double[][] points) {
- Plot myPlot = new Plot();
- myPlot.setTitle("Plot example");
- myPlot.setXLabel("x");
- myPlot.setYLabel("s(x)");
- int dl = points.length;
- myPlot.setMarksStyle("dots", 0);
- //myPlot.setImpulses(true, 0);
- //for(int i=0; i<ticks.length; i++) myPlot.addXTick("",ticks[i][0]);
- for (int i = 0; i < dl; i++) myPlot.addPoint(0, points[i][0], points[i][1], false);
- PlotApplication app = new PlotApplication(myPlot);
- app.setSize(800, 400);
- app.setLocation(100, 100);
- app.setTitle("MyPicture");
- }
- public static void main(String[] args) {
- int i = 3, j = 3;
- Matrix A = Matrix.random(i, j);
- Matrix B = Matrix.random(j, 1);
- Matrix D = new Matrix(i, j);
- Matrix R = new Matrix(i, j);
- Matrix I = Matrix.identity(i, j);
- Matrix x = new Matrix(i, 1);
- Matrix x1 = new Matrix(i, 1);
- for (int k = 0; k < i; k++) {
- for (int w = 0; w < j; w++) {
- if (k == w) {
- D.set(k, w, A.get(k, w));
- R.set(k, w, 0);
- } else {
- R.set(k, w, A.get(k, w));
- D.set(k, w, 0);
- }
- }
- }
- for (int k = 0; k < i; k++) {
- for (int w = 0; w < j; w++) {
- if (k == w) {
- D.set(k, w, 1 / D.get(k, w));
- }
- }
- }
- double norm = I.minus(D.times(A)).normInf();
- double norm1 = I.minus(D.times(A)).norm1();
- if (norm < 1 && norm1 < 1) {
- System.out.println("Macierz silnie dominujaca");
- System.out.println("normInf: " + norm);
- System.out.println("norm1: " + norm1);
- } else {
- System.out.println("Macierz nie jest scisle dominujaca");
- }
- for (int r = 0; r < 100; r++) {
- if (norm1 > 1 || norm > 1) {
- break;
- }
- if (x1.minus(x).normF() > 0.000001) {
- x1 = (I.minus(D.times(A))).times(x).plus(D.times(B));
- x = x1;
- break;
- }
- }
- System.out.println("normInf: " + norm);
- System.out.println("norm1: " + norm1);
- A.print(i, j);
- B.print(i, j);
- D.print(i, j);
- R.print(i, j);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement