Question
Write a matlab function to execute gaussian elimination with scaled partial pivoting based off of the following psuedo code: input variables: n (some number), a
Write a matlab function to execute gaussian elimination with scaled partial pivoting based off of the following psuedo code:
input variables: n (some number), aij (nxn coefficient array), li (the index array)
other terms and variables used si (scale array), denotes replacement of value with what is on the left, I believe in matlab an equal sign is what we're looking for.
Psuedo code:
function Gauss(n, (aij), (li))
integer i, j, k, n
real r, rmax, smax, xmult
real array (aij)1:n x 1:n, (li)1:n; real array allocate (si)1:n
%in the first loop the index array is being established li=i then scale array is computed
for i = 1 to n
lii
smax 0
for j =1 to n
smax max(smax, abs.value(aij)
end for
si smax
end for
for k = 1 to n-1 % initiating principle outer loop
%k is the subscript of the variable whose coefficients will be made 0 in the array (aij) in other words, k is the index of the %column in which ne 0's are being created
rmax 0
for i = k to n
% r is the ratio between the the array and scale array and used to determined the correct pivot row
r abs. value (aij/sl_i) %l_i = li
%calculating the gratest ratio rmax and the index j where it occurs
if (r > rmax) then
rmax r
j i
end if
end for
% lj and lk are swapped in array li
ljlk
%next loop makes the arithmetic modifications to aij due to subtracting multiples of row lk from rows lk+1, lk+2,..., ln. First the multiplier is computed and stored; then the subtraction occurs in a loop.
for i = k +1 to n
xmult al_i,k/al_k,k
al_i,k xmult
for j = k+1 to n
al_i,j al_i,j -(xmult)*al_k,j
end for
end for
end for
deallocate array (si)
end function Gauss
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started