Beruflich Dokumente
Kultur Dokumente
end
end
end
%
Backward substitution:
for
for
%
%
end
end
Submit
the
commented
program.
A.
2.
Use
your
program
to
solve
the
following
matrix
equation:
2 1 0 !
1
1 2 1
! = 2
0 1 2 !
3
Submit
the
output
from
the
program.
A.
3.
Use
your
program
to
solve
the
following
matrix
equation:
0 1 2 !
3
2 1 0 ! = 1
1 2 1 !
2
Submit
the
output
from
the
program.
Comment
briefly.
end
end
Submit
the
commented
program.
B.
2.
Use
your
program
to
solve
the
following
matrix
equation:
2 1 0 !
1
1 2 1 ! = 2
0 1 2 !
3
Submit
the
output
from
the
program.
B.
3.
Use
your
program
to
solve
the
following
matrix
equation:
0 1 2 !
3
2 1 0 ! = 1
1 2 1 !
2
Submit
the
output
from
the
program.
Comment
briefly.
where
E
is
the
modulus
of
elasticity,
I
is
the
area
moment
of
inertia
of
the
cross-section
of
the
beam
about
its
neutral
axis
(in
this
case,
I
is
constant),
y
is
the
deflection
of
the
beam
from
its
rest
position,
x
is
the
distance
along
the
beam,
and
M
is
the
bending
moment
about
the
origin
(x=0)
(in
this
problem,
the
bending
moment
is
a
function
of
x).
Divide
the
domain
into
11
elements
(i.e.
12
nodes,
with
10
of
these
nodes
being
interior;
n
=
10).
I
would
recommend
using
SI
units,
to
maintain
your
sanity.
Solve
the
problem
using
your
Gaussian
Elimination
program.
Plot
your
results
for
the
deflection
of
the
beam.
What
is
the
predicted
maximum
deflection
of
the
beam?
9/20/14 5:15 PM
C:\Users\PauloHenrique\Docu...\GaussElim.m
1 of 1
% Back Substitution
% Loop: row from # row down to 1
%
x(row,1) = [AugMatrix(row,#columns+1)-SUM[from col=row+1 to #columns](AugMatrix
(row,col)*x(col,1)]/AugMatrix(row,row)
% end
for row = rows:-1:1 %Because it's a back substitution, the size of x is limited by the
number of rows, so it's not necessary to define x before the loop
x(row,1) = AugMatrix(row,columns+1);
for col = row+1:columns
x(row,1) = x(row,1) - AugMatrix(row,col)*x(col,1);
end
x(row,1)=x(row,1)/AugMatrix(row,row);
end
return
9/20/14 5:26 PM
%
%
%
%
C:\Users\PauloHenriq...\GaussElimPartPiv.m
1 of 2
function x = GaussElimPartPiv(A, b)
[rows,columns] = size (A);
if rows ~= columns
error('Matrix A must be square.');
end
AugMatrix = [A b]; % Form the augmented matrix where the b colum is concatenated onto A
TempMatrix = zeros(1,columns+1);
% Forward Elimination with partial pivoting
for pivot = 1:rows-1
% Loop through pivots
maxElement = 0;
% Initialize maxElement and set it equal to 0 (it will zero after
each loop)
maxRow = 0;
% Initialize maxRow and set it equal to 0 (it will zero after each
loop)
% Partial pivoting
for rowPartPiv = pivot+1:rows % Loop through other rows
if maxElement == 0
%If this is the first loop or no values greater than the
pivot have been found
if AugMatrix(rowPartPiv, pivot) > AugMatrix(pivot, pivot) %Check to see if
entry is larger than pivot entry
maxElement = AugMatrix(rowPartPiv,pivot);
% Store value of the largest
entry
maxRow = rowPartPiv;
TempMatrix(1,:) = AugMatrix(pivot,:); % Store elements of pivot row
end
else
if AugMatrix(rowPartPiv, pivot) > maxElement % Check to see if entry is
larger than pivot entry
maxElement = AugMatrix(rowPartPiv,pivot);
% Store value of the
largest entry
maxRow = rowPartPiv;
TempMatrix(1,:) = AugMatrix(pivot,:); % Store elements of pivot row
end
end
end
if maxElement ~= 0
AugMatrix(pivot,:) = AugMatrix(maxRow,:);
% Place row with largest value in the
pivot position as a pivot
AugMatrix(maxRow,:) = TempMatrix(1,:);
% Place former pivot row where row
that took its place was
end
for row = pivot+1:rows % Loop through rows
factor = AugMatrix(row,pivot)/AugMatrix(pivot,pivot);
for col = pivot:columns+1
% Loop through columns
9/20/14 5:26 PM
C:\Users\PauloHenriq...\GaussElimPartPiv.m
AugMatrix(row,col) = AugMatrix(row,col)-factor*AugMatrix(pivot,col);
Eliminates elements below pivots
end
end
end
2 of 2
%
% Back Substitution
% Loop: row from # row down to 1
%
x(row,1) = [AugMatrix(row,#columns+1)-SUM[from col=row+1 to #columns](AugMatrix
(row,col)*x(col,1)]/AugMatrix(row,row)
% end
for row = rows:-1:1 %Because it's a back substitution, the size of x is limited by the
number of rows, so it's not necessary to define x before the loop
x(row,1) = AugMatrix(row,columns+1);
for col = row+1:columns
x(row,1) = x(row,1) - AugMatrix(row,col)*x(col,1);
end
x(row,1)=x(row,1)/AugMatrix(row,row);
end
return