Показать сообщение отдельно
  #1  
Старый 18.12.2010, 17:36
ittpqr ittpqr вне форума
Прохожий
 
Регистрация: 18.12.2010
Сообщения: 1
Репутация: 10
Восклицание Перемножение 2 матриц

Помогите сформировать алгорит для 3-го массива
подвох в том что нужно сделать универсальную программу в даном случае я рассматривал для матриц 1---2столбца 3 строки
2---- 3 столбца 2 строки
Код:
type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    StringGrid2: TStringGrid;
    StringGrid3: TStringGrid;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c:array of array of integer;
i,j,n,m,n1,m1,n2,m2:integer;

begin
n:=strtoint(edit1.Text);{количество строк}
m:=strtoint(edit2.Text);{количество столбцов}
n1:=strtoint(edit3.Text);{количество строк 2 матрицы}
m1:=strtoint(edit4.Text);{количество столбцов 2 матрицы}
setlength(a,n,m);
setlength(b,n1,m1);
if n<=n1 then n2:=n1 else n2:=n;
if m<=m1 then m2:=m1 else m2:=m;
setlength(c,n2,m2);
for i:=0 to n-1 do
for j:=0 to m-1 do
a[i,j]:=strtoint(stringgrid1.Cells[j,i]);
for i:=0 to n1-1 do
for j:=0 to m1-1 do
b[i,j]:=strtoint(stringgrid2.Cells[j,i]);
//for j:=0 to m2-1 do
//for i:=0 to n2-1 do
//for y:=0 to
//c[i,j]=a[i,0]*
c[0,0]:=a[0,0]*b[0,0]+a[0,1]*b[1,0];
c[1,0]:=a[1,0]*b[0,0]+a[1,1]*b[1,0];
c[2,0]:=a[2,0]*b[0,0]+a[2,1]*b[1,0];
c[0,1]:=a[0,0]*b[0,1]+a[0,1]*b[1,1];
c[1,1]:=a[1,0]*b[0,1]+a[1,1]*b[1,1];
c[2,1]:=a[2,0]*b[0,1]+a[2,1]*b[1,1];
stringgrid3.Cells[0,0]:=inttostr(c[0,0]);
stringgrid3.Cells[0,1]:=inttostr(c[1,0]);
stringgrid3.Cells[0,2]:=inttostr(c[2,0]);
end;

end.
Admin: Пользуемся тегами!

помогите
Ответить с цитированием