public class MultiMatrix {
double[]multiplyMatrix;
public static void main(String args[]){
double[] a={12,44,188};
double[][] b={{3,5,9},{6,2,7},{1,4,8}};
MultiMatrix mm=new MultiMatrix();
mm.mMatrix(a,b);
mm.display();
}
public void mMatrix(double[] a,double[][] b){
multiplyMatrix=new double[a.length];
for (int i = 0; i<a.length; i++) {//rows of a
for (int j = 0; j<b[0].length; j++) {//columns of b
//columns of a = rows of b
multiplyMatrix[i]+=a[j]*b[j][i];
}
}
}
public void display(){
for (int i = 0; i<multiplyMatrix.length; i++) {
System.out.print(multiplyMatrix[i]+" ");
}
}

解决方案 »

  1.   

    uses Types;{函数}
    function m(a:TDoubleDynArray; b: array of TDoubleDynArray): TDoubleDynArray;
    var
      I, J: Integer;
    begin
      SetLength(Result, Length(a));
      for I:=0 to High(a) do
      begin
        Result[I] := 0;
        for J:=0 to High(b) do
          Result[I] := Result[I] + a[J]*b[J][I]
      end;
    end;{调用}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      a:TDoubleDynArray;
      b: array of TDoubleDynArray;
      r: TDoubleDynArray;
      I: Integer;
    begin
      SetLength(a, 3);
      a[0]:=12;a[1]:=44;a[2]:=188;  SetLength(b, 3);
      for I:=0 to High(b) do
        SetLength(b[I], 3);
      b[0][0]:=3;b[0][1]:=5;b[0][2]:=9;
      b[1][0]:=6;b[1][1]:=2;b[1][2]:=7;
      b[2][0]:=1;b[2][1]:=4;b[2][2]:=8;  r := m(a, b);
      showmessagefmt('%f,%f,%f', [r[0],r[1],r[2]])
    end;