主题:初学者紧急求救!
求救,毕业设计没几天了,做不出来。没学过java,但不得不用,以下代码总是提示
ivector = m2.times(m).times(h); //特征向量增量
行矩阵内部错误,貌似是说矩阵行列数不一致还是什么的。求大神帮助
package aa;
import Jama.Matrix;
public class e2 {
private e1 e11;
private int an= 10;
private double val= 0.18;
public e2(e1 e11){
this.e11 = e11;
}
public void update(){
Matrix uijm = new Matrix(an,1);
Matrix uijmt = new Matrix(1,an);
Matrix diagm = new Matrix(an,an);
Matrix iLm = new Matrix (an,an);
Matrix iDm = new Matrix(an,an);
Matrix Km = new Matrix(an,an);
Matrix h = new Matrix(an,1);
Matrix ivector = new Matrix(an,1);
double ivalue = 0;
double a,b,c,d = 0;
double increw = 0.9;
for(int i=0;i<an;i++){
ivector.set(i, 0, 0);
}
Matrix unlaplam = e11.getUnLaplaM();
Matrix diaglom = e11.getDiagoM();
double[][] vec1 ={{0.30},
{0.37},
{0.38},
{0.17},
{0.09},
{-0.10},
{-0.35},
{-0.44},
{-0.42},
{-0.32}};
Matrix vec = new Matrix(vec1);
int i = 3;
int j = 6;
a = Math.pow((vec.get(i,0)-vec.get(j,0)),2)-val*(Math.pow(vec.get(i,0),2)+Math.pow(vec.get(j,0),2));
b = (vec.get(i,0)-vec.get(j,0))*(ivector.get(i,0)-ivector.get(j,0))-val*(vec.get(i,0)*ivector.get(i,0)-vec.get(j,0)*ivector.get(j,0));
c = increw*(Math.pow(vec.get(i,0),2)-Math.pow(vec.get(j,0),2));
for (int k=0;k<an;k++){
d += vec.get(k,0)*diaglom.get(k,k)*ivector.get(k,0);
}
ivalue = increw*(a+b)/(1+c+d); //特征值增量
Km = unlaplam.minus(diaglom.times(val));
h = (diaglom.times(ivalue).plus(iDm.times(val)).minus(iLm)).times(vec.get(i,0));
Matrix m = transpose(Km);
Matrix m1 = m.times(Km);
Matrix m2 = inverse(m1);
ivector = m2.times(m).times(h); //特征向量增量
for(int f=0;f<an;f++){
if(f==i){
uijm.set(f,0,1);
diagm.set(f,f,1);
uijmt.set(0,f,1);
}
if(f==j){
uijm.set(f,0,-1);
diagm.set(f,f,1);
uijmt.set(0,f,-1);
}
}
iLm = uijm.times(uijmt).times(increw); // 拉氏矩阵增量
iLm.print(4,2);
iDm = diagm.times(increw); //度矩阵增量
unlaplam = unlaplam.plus(iLm);
diaglom = diaglom.plus(iDm);
//diaglom.print(4,2);
System.out.println("特征值增量为"+ivalue);
System.out.println("特征向量增量为");
ivector.print(4, 2);
Matrix out = vec.plus(ivector);
System.out.println("增量计算后的特征向量:");
out.print(4, 2);
}
private Matrix inverse(Matrix m) {
int i = 8;
int j = 8;
double[][] Vp = new double[20][20];
for(int k=0;k<20;k++)
{
for(int t=0;t<20;t++)
{
Vp[k][t]= 0.0;
}
}
for(int k=1;k<=8;k++)
{
for(int t=1;t<=8;t++)
{
Vp[k][t] = (float) m.get(k-1,t-1);
}
}
for(int k=1;k<=i;k++)
{
for(int t=j+1;t<=j*2;t++)
{
if((t-k)==j)
{
Vp[k][t]=1.0;
}
else
{
Vp[k][t]=0;
}
}
}
for(int k=1;k<=i;k++)
{
if(Vp[k][k]!=1)
{
double bs = Vp[k][k];
Vp[k][k]=1;
for(int p=k+1;p<=j*2;p++)
{
Vp[k][p]/=bs;
}
}
for(int q=1;q<=i;q++)
{
if(q!=k)
{
double bs = Vp[q][k];
for(int p=1;p<=j*2;p++)
{
Vp[q][p]-=bs*Vp[k][p];
}
}
else
{
continue;
}
}
}
double[][] vp = new double[8][8];
for(int k=1;k<=8;k++){
for(int t=1;t<=8;t++){
vp[k-1][t-1] = Vp[k][t];
}
}
Matrix kmm = new Matrix(vp);
return kmm;
}
private Matrix transpose(Matrix km) {
double[][] temp = new double[an][an];
for (int i = 0; i < an; i++) {
for (int j = 0; j < an; j++) {
temp[j][i] = (double) km.get(i,j);
}
}
Matrix kmm = new Matrix(temp);
return kmm;
}
public static void main(String[] args) {
e1 e11= new e1();
e2 e22 = new e2(e11) ;
e22.update();
}
}
[em10][em10]
ivector = m2.times(m).times(h); //特征向量增量
行矩阵内部错误,貌似是说矩阵行列数不一致还是什么的。求大神帮助
package aa;
import Jama.Matrix;
public class e2 {
private e1 e11;
private int an= 10;
private double val= 0.18;
public e2(e1 e11){
this.e11 = e11;
}
public void update(){
Matrix uijm = new Matrix(an,1);
Matrix uijmt = new Matrix(1,an);
Matrix diagm = new Matrix(an,an);
Matrix iLm = new Matrix (an,an);
Matrix iDm = new Matrix(an,an);
Matrix Km = new Matrix(an,an);
Matrix h = new Matrix(an,1);
Matrix ivector = new Matrix(an,1);
double ivalue = 0;
double a,b,c,d = 0;
double increw = 0.9;
for(int i=0;i<an;i++){
ivector.set(i, 0, 0);
}
Matrix unlaplam = e11.getUnLaplaM();
Matrix diaglom = e11.getDiagoM();
double[][] vec1 ={{0.30},
{0.37},
{0.38},
{0.17},
{0.09},
{-0.10},
{-0.35},
{-0.44},
{-0.42},
{-0.32}};
Matrix vec = new Matrix(vec1);
int i = 3;
int j = 6;
a = Math.pow((vec.get(i,0)-vec.get(j,0)),2)-val*(Math.pow(vec.get(i,0),2)+Math.pow(vec.get(j,0),2));
b = (vec.get(i,0)-vec.get(j,0))*(ivector.get(i,0)-ivector.get(j,0))-val*(vec.get(i,0)*ivector.get(i,0)-vec.get(j,0)*ivector.get(j,0));
c = increw*(Math.pow(vec.get(i,0),2)-Math.pow(vec.get(j,0),2));
for (int k=0;k<an;k++){
d += vec.get(k,0)*diaglom.get(k,k)*ivector.get(k,0);
}
ivalue = increw*(a+b)/(1+c+d); //特征值增量
Km = unlaplam.minus(diaglom.times(val));
h = (diaglom.times(ivalue).plus(iDm.times(val)).minus(iLm)).times(vec.get(i,0));
Matrix m = transpose(Km);
Matrix m1 = m.times(Km);
Matrix m2 = inverse(m1);
ivector = m2.times(m).times(h); //特征向量增量
for(int f=0;f<an;f++){
if(f==i){
uijm.set(f,0,1);
diagm.set(f,f,1);
uijmt.set(0,f,1);
}
if(f==j){
uijm.set(f,0,-1);
diagm.set(f,f,1);
uijmt.set(0,f,-1);
}
}
iLm = uijm.times(uijmt).times(increw); // 拉氏矩阵增量
iLm.print(4,2);
iDm = diagm.times(increw); //度矩阵增量
unlaplam = unlaplam.plus(iLm);
diaglom = diaglom.plus(iDm);
//diaglom.print(4,2);
System.out.println("特征值增量为"+ivalue);
System.out.println("特征向量增量为");
ivector.print(4, 2);
Matrix out = vec.plus(ivector);
System.out.println("增量计算后的特征向量:");
out.print(4, 2);
}
private Matrix inverse(Matrix m) {
int i = 8;
int j = 8;
double[][] Vp = new double[20][20];
for(int k=0;k<20;k++)
{
for(int t=0;t<20;t++)
{
Vp[k][t]= 0.0;
}
}
for(int k=1;k<=8;k++)
{
for(int t=1;t<=8;t++)
{
Vp[k][t] = (float) m.get(k-1,t-1);
}
}
for(int k=1;k<=i;k++)
{
for(int t=j+1;t<=j*2;t++)
{
if((t-k)==j)
{
Vp[k][t]=1.0;
}
else
{
Vp[k][t]=0;
}
}
}
for(int k=1;k<=i;k++)
{
if(Vp[k][k]!=1)
{
double bs = Vp[k][k];
Vp[k][k]=1;
for(int p=k+1;p<=j*2;p++)
{
Vp[k][p]/=bs;
}
}
for(int q=1;q<=i;q++)
{
if(q!=k)
{
double bs = Vp[q][k];
for(int p=1;p<=j*2;p++)
{
Vp[q][p]-=bs*Vp[k][p];
}
}
else
{
continue;
}
}
}
double[][] vp = new double[8][8];
for(int k=1;k<=8;k++){
for(int t=1;t<=8;t++){
vp[k-1][t-1] = Vp[k][t];
}
}
Matrix kmm = new Matrix(vp);
return kmm;
}
private Matrix transpose(Matrix km) {
double[][] temp = new double[an][an];
for (int i = 0; i < an; i++) {
for (int j = 0; j < an; j++) {
temp[j][i] = (double) km.get(i,j);
}
}
Matrix kmm = new Matrix(temp);
return kmm;
}
public static void main(String[] args) {
e1 e11= new e1();
e2 e22 = new e2(e11) ;
e22.update();
}
}
[em10][em10]