这是在DFM.java中
这部分属于主要课程
Algebra.vect dx = new Algebra.vect(new double[] {2.0,3.0,4.0});
Algebra.matrix eij = new Algebra.matrix();
System.out.println(eij.get(1,1));
dx.set(1,4.0);
System.out.println(dx.get(1));
这是在Algebra.java中
class Algebra {
public static class vect
{
double[] v = new double[3];
public vect()
{
v[0]=v[1]=v[2]=0;
}
public vect(double[] v)
{
this.v=v;
}
int tamanho()
{
return v.length;
}
double get(int i)
{
return v[i];
}
void set(double[] v)
{
this.v=v;
}
void set(int i, double n)
{
v[i]=n;
}
void print()
{
for(int i=0; i < v.length; i = i + 1)
System.out.print(v[i] + " ");
System.out.print("
");
}
}
public static class operacoes
{
double prodInt(vect v1, vect v2)
{
return v1.get(0)*v2.get(0)+v1.get(1)*v2.get(1)+v1.get(2)*v2.get(2);
}
double[] somaVV(vect v1, vect v2)
{
return new double[] {v1.get(0)+v2.get(0), v1.get(1)+v2.get(1), v1.get(2)+v2.get(2) };
}
double[] prodMV(matrix m, vect v)
{
double[] Soma = new double[3];
Soma[0]=Soma[1]=Soma[2]=0;
for(int i=0;i< v.tamanho();i=i+1)
{
for(int j=0;i< v.tamanho();j=j+1)
{
Soma[i]=m[i][j]*v[j];
}
}
return Soma;
}
}
public static class matrix
{
double[][] m = new double[3][3];
public matrix()
{
for(int i=0;i< v.tamanho();i=i+1)
{
for(int j=0;i< v.tamanho();j=j+1)
{
m[i][j]=0;
}
}
}
public matrix(double[][] m )
{
this.m=m;
}
double get(int i,int j)
{
return m[i][j];
}
void set(double [][] m)
{
this.m=m;
}
void set(int i,int j, double n)
{
m[i][j]=n;
}
void print()
{
for(int i=0;i< v.tamanho();i=i+1)
{
for(int j=0;i< v.tamanho();j=j+1)
{
System.out.print(m[i][j] + " ");
}
System.out.print("
");
}
System.out.print("
");
}
}
错误
DFM.java:29: error: cannot find symbol
System.out.println(eij.get(1,1));
^
symbol: method get(int,int)
location: variable eij of type matrix
1 error
但是当我在评论中使用eij方法调用时
dx.set(1,4.0);
System.out.println(dx.get(1));
这部分dx是vect类,
效果很好,代码类似于矩阵类
有人可以帮忙吗?