Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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), image text in transcribed 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

liimage text in transcribedi

smaximage text in transcribed 0

for j =1 to n

smax image text in transcribed max(smax, abs.value(aij)

end for

si image text in transcribed 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 image text in transcribed 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 image text in transcribed 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 image text in transcribed r

j image text in transcribed i

end if

end for

% lj and lk are swapped in array li

ljimage text in transcribedlk

%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 image text in transcribed al_i,k/al_k,k

al_i,kimage text in transcribed xmult

for j = k+1 to n

al_i,j image text in transcribedal_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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions