expecting EOF, found 'columns'..cant figure it out
in
Programming Questions
•
11 months ago
Could somebody help me solving the error??
I couldn't figure it out..
The 1st code will run without any problem..
I couldn't figure it out..
The 1st code will run without any problem..
- String rows[] = loadStrings("Head.txt"); //read txt files
- String[] columns;
- columns = splitTokens(rows[0]); //how many columns in a line in txt file
- double[][] matrixA = new double[rows.length][columns.length];
- double[][] transposed_matrixA = new double[columns.length][rows.length];
- double[][] covariance_matrixA = new double[columns.length][columns.length];
- double[] Mean = new double[columns.length];
- double[][] X = new double[columns.length][rows.length];
- double[][] transposed_X = new double[rows.length][columns.length];
- //double[][] V = new double[columns.length][columns.length];
- //double[][] D = new double[columns.length][columns.length];
-
- //check the size of input matrix from the .txt file
- println("there are " + rows.length + " rows");
- println("there are " + columns.length + " columns");
- //insert the numbers from txt file into matrixA
- for (int i =0 ; i<rows.length; i++){
- columns = splitTokens(rows[i]);
- for(int j=0; j<columns.length; j++){
- matrixA[i][j] = Double.parseDouble(columns[j]);
- transposed_matrixA[j][i] = matrixA[i][j];
- }
- }
- //calculate means for transposed_matrixA.So we have to change rows to columns and vice versa
- for(int i=0; i<columns.length; i++){
- double mean = 0.0;
- for(int j=0; j<rows.length; j++){
- mean += transposed_matrixA[i][j];
- }
- Mean[i] = mean/rows.length;
- }
- for(int i=0; i<columns.length; i++){
- for(int j=0; j<rows.length; j++){
- X[i][j] = transposed_matrixA[i][j] - Mean[i];
- transposed_X[j][i] = X[i][j];
- }
- }
- for(int i=0; i<columns.length; i++){
- for(int j=0; j<columns.length; j++){
- for(int k=0; k<rows.length; k++){
- covariance_matrixA[i][j] += X[i][k]*transposed_X[k][j];
- }
- covariance_matrixA[i][j] /= rows.length;
- }
- }
But when I add a code as below whether in a new tab or below line 50 of above code, I got an error stating " expecting EOF, found 'columns' " that is highlighted at the 3rd line of above code..The weird part is,even i commented out below's code, the error still remains..only when I erase the code that the error will gone..
Help please
Help please
![](zoho-static/ze/images/emotions_cry.gif)
- class jacobi{
- static final double EPS = pow(10,-6);
- static final double TINY = pow(10,-20);
- static final int MAX=ITER = 100;
- static void kaiten(double[][] a, int i, int j, int k, int l, double c, double s){
- double x = a[i][j], y = a[k][l];
- a[i][j] = x*c - y*s;
- a[k][l] = x*s + y*c;
- }
-
- public static boolean solve(double[][] a, double[][] w){
- int n = a.length;
- double s = 0, offdiag = 0;
- for(int j=0; j<n; j++){
- for(int k=0; k<n; k++){
- w[j][k] = 0;
- }
- w[j][j] = 1; s += a[j][j] * a[j][j];
- for(int k = j+1; k<n; k++){
- offdiag += a[j][k];
- }
- }
-
- double tolerance = EPS * EPS * (s/2 + offdiag);
- int iter;
-
- for(iter=1; iter<=MAX_ITER; iter++){
- offdiag = 0;
- for(int j=0; j<n-1; j++){
- for(int k=j+1; k<n; k++){
- offdiag += a[j][k] * a[j][k];
- }
- println(iter + " : " + sqrt(2*offdiag / (n*(n-1))));
- }
-
- if(offdiag<tolerance){
- break;
- }
- for(int j=0; j<n-1; j++){
- for(int k=j+1; k<n; k++){
- if(abs(a[j][k]) < TINY){
- continue;
- }
- double t = (a[k][k] - a[j][j]) / (2 * a[j][k]);
- if(t >= 0){
- t = 1 /(t + sqrt(t*t + 1));
- }
- else{
- t = 1/(t - sqrt(t*t + 1));
- }
- double c = 1/sqrt(t*t + 1), u = t*c;
- t *= a[j][k];
- a[j][j] -= t; a[k][k] += t; a[j][k] = 0;
- int i;
- for(i=0; i<j; i++) {
- kaiten(a,i,j,i,k,c,u);
- }
- for(i=j+1; i<k; i++) {
- kaiten(a,j,i,i,k,c,u);
- }
- for(i=k+1; i<n; i++) {
- kaiten(a,j,i,k,i,c,u);
- }
- for(i=0; i<n; i++) {
- kaiten(w,j,i,k,i,c,u);
- }
- }
- }
- }
- if(iter > MAX_ITER) return false;
- for(int i=0; i<n-1; i++){
- int k=i; double t=a[k][k];
- for(int j=i+1; j<n; j++){
- if(a[j][j] > t){
- k=j; t=a[k][k];
- }
- }
- a[k][k] = a[i][i]; a[i][i] = t;
- double[] v = w[k]; w[k] = w[i]; w[i] = v;
- }
- return true;
- }
- }
1