-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphNoSort.java
More file actions
99 lines (80 loc) · 2.59 KB
/
GraphNoSort.java
File metadata and controls
99 lines (80 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Jacobian;
import java.awt.*;
import javax.swing.*;
import Jama.Matrix;
import java.util.ArrayList;
/**
*
* @author Anthony Stange
*/
public class GraphNoSort extends JPanel{
private static final long serialVersionUID = -7365703762651574779L;
private ArrayList<Double> bK;
private int run;
private String output;
private Matrix m, orig;
/**
* Creates the Panel to store the graph
* and sets run to 0 and the current matrix to 1
*/
public GraphNoSort() {
setPreferredSize(new Dimension(700,300));
setBackground(Color.white);
run = 0;
}
/**
* When my driver tells the program to run the method generates
* 10 random matrices and runs the jacobi no sort algorithm
* on them
*/
public void run(){
//resets the output string
output = "";
//resets the bK variable
bK = new ArrayList<Double>();
output += "OffB values for No Sort Method: " + "\n";
//Creates a random matrix
m = Matrix.random(5, 5);
//makes the matrix symmetric
m = m.transpose().times(m);
//puts the untouched matrix in the original array that contains
//the originals of all the matrices
orig = m;
//Performs the offB diagonalization on the matrix
ArrayList<Double> list = JacobianNoSort.getOffBs(m);
//adds the ln(offBs) to the bK array list
for (double item : list) {
bK.add(Math.log(item));
}
//Also puts all the offBs in a string format so we can see them
//printed on the screen
output += "\n";
for(double item: list){
output += item + "\n";
}
output += "\n";
//increments run so the graph will display the bk values
run++;
}
//returns the offBs for all ten matrices
public String getOffB(){
return output;
}
//If run() has been run the graph will display the boundary
//in blue and the matrix in black
public void paintComponent(Graphics g) {
super.paintComponent(g);
if(run == 1){
g.setColor(Color.blue);
g.drawLine(0,150,700,150);
g.drawLine(0,(int)(-Math.log(JacobianNoSort.offA(orig)) + 150),700, 75 - (int)Math.log(JacobianNoSort.offA(orig))+150);
g.setColor(Color.BLACK);
for (int i = 0; i < bK.size(); i++) {
g.drawOval(i * 5, (int) (-bK.get(i) + 150),2,2);
}
}
//resets variables
run = 0;
output = "";
}
}