Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Adjusting a do loop for matrix algebra? ----- I am trying to write a program in

ID: 3807040 • Letter: A

Question

Adjusting a do loop for matrix algebra?

-----

I am trying to write a program in Maple to create a lower-triangular matrix. My professor provided a do loop in class that creates an upper-triangular matrix, but I don't even understand how that works, so I can't change the code to make it create a lower-triangular matrix instead.

Given the matrix A:

I can use the code:

for j to 4 do

for i to 4 do

if i > j then

c := -A[i, j]/A[j, j];

for k to 4 do

A[i, k] := c*A[j, k]+A[i, k]

end do

end if

end do

end do;

... which results in the matrix,

How can I adjust this code to make it do lower-triangular instead? I don't even understand the upper-triangular code. I understand Gaussian elimination, but I don't understand how this code works because of the nested loops.

3 1 0 10 21 1021 421 12 12

Explanation / Answer

for i to 4 do

for j to 4 do

C[i,j] := A[i,j]

end do

end do

for i to 4 do

for j to 4 do

A[i,j] := C[j,i]

end do

end do

for j to 4 do

for i to 4 do

if i > j then

c := -A[i, j]/A[j, j];

for k to 4 do

A[i, k] := c*A[j, k]+A[i, k]

end do

end if

end do

end do

for i to 4 do

for j to 4 do

C[i,j] := A[i,j]

end do

end do

for i to 4 do

for j to 4 do

A[i,j] := C[j,i]

end do

end do

Explaination :- we have converted the original matrix into mirror image of that matrix such that A[i,j] = A[j,i]. Now we will use the usual code to convert into upper triangular matrix and then again do the same swap to get back lower triangular matrix.