Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import Jama.Matrix;
- import ptolemy.plot.Plot;
- import ptolemy.plot.PlotApplication;
- import java.util.Random;
- public class Main {
- static Plot myPlot = new Plot();
- static int N = 50;
- static int M = 0;
- public static double FI = 360/N;
- public static double R = 5;
- public static double [][] tab = new double [N][];
- public static double [][] tab2 = new double [N][];
- public static double [][] tab3 = new double [360][];
- public static double [][] tab4 = new double [360][];
- public static Random generator = new Random();
- public static void main(String[] args)
- {
- generujPunkty();
- wypiszTablice();
- rysujTablice();
- Matrix A = getAMacierz();
- Matrix B = getBMacierz();
- Matrix dekomp = A.solve(B);
- System.out.println("Dekomp: ");
- dekomp.print(5,2);
- for(int i=0; i<360;i++)
- {
- double odleglosc = getR(dekomp,i);
- double x = odleglosc*Math.cos(Math.toRadians(i));
- double y = odleglosc*Math.sin(Math.toRadians(i));
- double [] temp = {x,y};
- tab3[i] = temp;
- }
- rysujTablice2();
- }
- public static void generujPunkty()
- {
- double kat = FI;
- for(int i=0; i<N;i++)
- {
- double rad = Math.toRadians(kat);
- double r = R + generator.nextDouble();
- double x = r * Math.cos(rad);
- double y = r * Math.sin(rad);
- double temp[] = {x,y};
- double temp2[] ={rad,r};
- tab[i]= temp;
- tab2[i] = temp2;
- kat += FI;
- System.out.println("KAT "+rad + " r " +r + " x= "+x + " y= "+y);
- }
- }
- public static void wypiszTablice()
- {
- for(int i=0; i<N; i++)
- {
- System.out.println("x = "+tab[i][0] + " y = "+ tab[i][1]);
- }
- }
- public static void rysujTablice() {
- myPlot.setTitle("Plot example");
- myPlot.setXLabel("x");
- myPlot.setYLabel("s(x)");
- int dl = tab.length;
- myPlot.setMarksStyle("dots", 0);
- //myPlot.setImpulses(true, 0);
- for (int i = 0; i < dl - 1; i++) myPlot.addPoint(0, tab[i][0], tab[i][1], false);
- PlotApplication app = new PlotApplication(myPlot);
- app.setSize(800, 400);
- app.setLocation(100, 100);
- app.setTitle("MyPicture");
- }
- public static void rysujTablice2() {
- myPlot.setTitle("Plot example");
- myPlot.setXLabel("x");
- myPlot.setYLabel("s(x)");
- int dl = tab3.length;
- myPlot.setMarksStyle("dots", 0);
- //myPlot.setImpulses(true, 0);
- for (int i = 0; i < dl - 1; i++) myPlot.addPoint(0, tab3[i][0], tab3[i][1], true);
- PlotApplication app = new PlotApplication(myPlot);
- app.setSize(800, 400);
- app.setLocation(100, 100);
- app.setTitle("MyPicture");
- }
- public static Matrix getAMacierz()
- {
- int m = (N-1)/2;
- M = m;
- Matrix mat = new Matrix(N,m);
- int index =1;
- for(int i=0;i<N;i++)
- {
- for(int k=0;k<m; k++)
- {
- if(k==0)
- mat.set(i,k,1);
- else if(k%2==0)
- {
- double teta = tab2[i][0];
- mat.set(i,k,Math.sin(teta*index));//sin
- index++;
- }
- else
- {
- double teta = tab2[i][0];
- mat.set(i,k,Math.cos(teta*index));//cos
- }
- }
- index = 1;
- }
- mat.print(5,2);
- return mat;
- }
- public static Matrix getBMacierz()
- {
- Matrix mat = new Matrix(N,1);
- for(int i=0; i<mat.getRowDimension();i++)
- {
- mat.set(i,0,tab2[i][1]);
- }
- System.out.println("Macierz b");
- mat.print(5,2);
- return mat;
- }
- public void dekomp(Matrix A)
- {
- Matrix x = new Matrix(2*M+1,1);
- for(int k=0; k<A.getColumnDimension();k++)
- {
- for(int i=0; i<A.getRowDimension();i++)
- {
- }
- }
- }
- public static double getR(Matrix x, double kat)
- {
- double wartosc = 0;
- for(int i=0;i<x.getRowDimension();i++)
- {
- if(i==0)
- wartosc+=x.get(0,0);
- else if(i%2==1)
- {
- wartosc+=x.get(i,0)*Math.cos(Math.toRadians(kat));
- }else
- {
- wartosc += x.get(i,0)*Math.sin(Math.toRadians(kat));
- }
- }
- return wartosc;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement