![]() |
Прежде чем задать вопрос, смотрите FAQ.
Рекомендуем загрузить DRKB.
![]() |
Pirate |
![]()
Сообщение
#1
|
Новичок ![]() Группа: Пользователи Сообщений: 21 Пол: Мужской Реальное имя: Лёха Репутация: ![]() ![]() ![]() |
Помогите найти ошибку ,мне нужно найти обратную матрицу(Процедура Inv_m) не могу понять где ошибка или я что-то сделал не так?
procedure TForm1.SpinEdit1Change(Sender: TObject); begin kol:= SpinEdit1.Value; StringGrid1.ColCount:= kol; StringGrid1.RowCount:= kol; end; procedure Inv_M; var k, i, j: integer; b: array[0..100, 0..100] of real; begin for k:=0 to kol-1 do begin for i:=0 to kol-1 do for j:=0 to kol-1 do begin if (i=k) and (j=k) then b[i,j] := 1/a[i,j]; if (i=k) and (j<>k) then b[i,j] := -a[i,j]/a[k,k]; if (i<>k) and (j=k) then b[i,j] := a[i,k]/a[k,k]; if (i<>k) and (j<>k) then b[i,j] := a[i,j] - a[k,j] * a[i,k]/a[k,k]; end; for i:= 0 to kol-1 do for j:= 0 to kol-1 do a[i, j]:= b[i, j]; end; end; procedure TForm1.Button1Click(Sender: TObject); begin try for i:=0 to StringGrid1.RowCount-1 do begin for j:=0 to StringGrid1.RowCount-1 do A[j,i] := strtofloat(StringGrid1.Cells[i,j]) / strtofloat(StringGrid1.Cells[StringGrid1.ColCount-1,i]); A[i,j]:=A[j,i]; end; begin for i:=0 to StringGrid1.RowCount-1 do for j:=0 to StringGrid1.RowCount-1 do if i=j then a[i,j]:=1-a[i,j] else a[i,j]:=-a[i,j]; end; Inv_M; for i:=0 to StringGrid1.RowCount-1 do begin for j:=0 to StringGrid1.RowCount-1 do s := s + ' ' + FormatFloat('0.00',a[i,j]); s := s + #13#10; end; Memo1.Text := s; except on EConvertError do MessageBox(Form1.Handle,'Íåïðàâèëüíûé ââîä äàííûõ!',nil,0); on EZeroDivide do MessageBox(Form1.Handle,'Äåëåíèå íà íîëü íàõ!',nil,0); end; end; |
![]() ![]() |
![]() |
Текстовая версия | 29.07.2025 21:00 |