// ArraySize 就是你要几维的矩阵
TYPE
PTNM = ^TNmatrix;
TNvector = ARRAY[1..TNArraySize] OF Float;
TNmatrix = ARRAY[1..TNArraySize] OF TNvector;
VAR
Mat : PTNM
{ given square symmetric matrix }
PROCEDURE RotateMatrix(Dimen : integer;
SinTheta : Float;
CosTheta : Float;
Row : integer;
Col : integer);
VAR
CosSqr, SinSqr, SinCos : Float;
MatRowRow, MatColCol, MatRowCol, MatRowIndex, MatColIndex : Float;
Index : integer;
BEGIN
CosSqr := Sqr(CosTheta)
SinSqr := Sqr(SinTheta);
SinCos := SinTheta * CosTheta;
MatRowRow := Mat^[Row, Row] * CosSqr + 2 * Mat^[Row, Col] * SinCos +
Mat^[Col, Col] * SinSqr;
MatColCol := Mat^[Row, Row] * SinSqr - 2 * Mat^[Row, Col] * SinCos +
Mat^[Col, Col] * CosSqr;
MatRowCol := (Mat^[Col, Col] - Mat^[Row, Row]) * SinCos +
Mat^[Row, Col] * (CosSqr - SinSqr);
FOR Index := 1 to Dimen DO
IF NOT(Index IN [Row, Col]) THEN
BEGIN
MatRowIndex := Mat^[Row, Index] * CosTheta +
Mat^[Col, Index] * SinTheta;
MatColIndex := -Mat^[Row, Index] * SinTheta +
Mat^[Col, Index] * CosTheta;
Mat^[Row, Index] := MatRowIndex;
Mat^[Index, Row] := MatRowIndex;
Mat^[Col, Index] := MatColIndex;
Mat^[Index, Col] := MatColIndex;
END;
Mat^[Row, Row] := MatRowRow;
Mat^[Col, Col] := MatColCol;
Mat^[Row, Col] := MatRowCol;
Mat^[Col, Row] := MatRowCol;
END;