You are only using single-letter variable names. While this is quite understandable for
C, I don't recommend it for
The big problem about
j) is that it is hard to tell what is the row and what is the column. (The thing I hate the most about mathematics is the undescriptive variable names, it is not something I'd personally recommend carrying over to the programming side of things)
Speaking of names, your method is named
E. That really doesn't say anything whatsoever.
I believe it's convention in Delphi to use an uppercase letter for the
T prefix, so that would be
I'd use slightly more spacing in the code, and I'd also use a
begin also for the outer for-loop.
if i<=j then C[i,j]:=A[i,j] + B[i,j] else C[i,j]:=A[i,j] - B[i,j];
is, except for the short and confusing variable names, not that bad really. I think it boils down to opinions how to write it 'the best'. An alternative to what you are doing is to use a
procedure ConditionallyAdd(rows, cols: Integer; A, B: TMatrix; var C: TMatrix);
row, col: Integer;
addValue: Real; // or Integer? or something. The type that your matrix uses
for row := 1 to rows do begin
for col := 1 to cols do begin
if row <= col then addValue = B[row, col];
else addValue = -B[row, col];
C[row, col] := addValue;
There is essentially a lot of different ways to write this. Use the way you like the best.
I suspect that the integer values passed to the procedure always match the size of the matrices, in that case, use rows and cols as properties of the matrices if possible.