Вы находитесь на странице: 1из 12

Name: Lourvic Ellisa F.

Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
Ateneo de Naga University
College of Engineering
Department of ECE and CpE
Numerical Methods Laboratory [ECEM428LAB]

I. Problem:
Make a function of your Naive Gauss Elimination.
II. Theory:
Naive Gauss Elimination


GE41


Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:




Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:




Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
II. Answers:
Codes (MATLAB)
function x = naivegauss(varargin)
%Input the function
for i=1:nargin
gauss(i) = varargin(i);
end
naive = cell2mat(gauss')
[m,n]=size(naive);
for a=1:m
for i = 1:length(naive)-1
limiter(a,i) = naive(a,i);
end
end

[m,n] = size(limiter);
if m~=n, error('Matrix A must be square');
end
ok=n+1;

%forward elimination
for b = 1:n-1
[big,i] = max(abs(naive(b:n,b)));
y = i+b-1;
if y ~=b
naive([b,y],:) = naive([y,b],:);
end
for i = b+1:n
factor = naive(i,b)/naive(b,b);
naive(i,b:ok) = naive(i,b:ok) - factor*naive(b,b:ok);
end
end
naive
%backward substitution
x = zeros(n,1);
x(n)=naive(n,ok)/naive(n,n);
for i = n-1:-1:1
x(i)=(naive(i,ok)-naive(i,i+1:n)*x(i+1:n))/naive(i,i);
end
end




Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
Output
For 2 unknowns

For 3 unknowns




Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
For 4 unknowns









Ateneo de Naga University

GE41


Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
College of Engineering
Department of ECE and CpE
Numerical Methods Laboratory [ECEM428LAB]

I. Problem:
Make a function of your Gauss Jordan Elimination.
II. Theory:
Gauss Jordan Elimination
Introduction
We will now explore a more versatile way than the method of determinants to determine
if a system of equations has a solution. We will indeed be able to use the results of this
method to find the actual solution(s) of the system (if any). It should be noted that this
method can be applied to systems of equations with an unequal number of equations and
unknowns. However, we will only discuss systems with an equal number of equations and
unknowns.
It is easiest to illustrate this method with an example. Consider the system of equations

To solve for x, y, and z we must eliminate some of the unknowns from some of the
equations. Consider adding -2 times the first equation to the second equation and also
adding 6 times the first equation to the third equation. The result is

We have now eliminated the x term from the last two equations. Now simplify the last two
equations by dividing by 2 and 3, respectively:



Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
To eliminate the y term in the last equation, multiply the second equation by -5 and add it
to the third equation:

The third equation says z=-2. Substituting this into the second equation yields y=-1. Using
both of these results in the first equation gives x=3. The process of progressively solving
for the unknowns is called back-substitution.
This is the essence of Gaussian elimination. However, we may clean up the notation in our
work by using matrices.
Gaussian Elimination
Convert the system of equations above into an augmented matrix:

This matrix contains all of the information in the system of equations without the x, y, and
z labels to carry around. Now carry out the process outlined above. The notation to the
right of each matrix describes the row operations that were performed to get the matrix
on that line. For example 2R_1+R_2 -> R_2 means "replace row 2 with the sum of 2 times
row 1 and row 2".





Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
If we now reverse the conversion process and turn the augmented matrix into a system of
equations we have

We can now easily solve for x, y, and z by back-substitution.
II. Answers:
Codes (MATLAB)
function x = naivegauss(varargin)
%Input the function
for i=1:nargin
gauss(i) = varargin(i);
end
naive = cell2mat(gauss')
[m,n]=size(naive);
for a=1:m
for i = 1:length(naive)-1
limiter(a,i) = naive(a,i);
end
end

[m,n] = size(limiter);
if m~=n, error('Matrix A must be square');
end
ok=n+1;

%forward elimination
for b = 1:n-1
[big,i] = max(abs(naive(b:n,b)));
y = i+b-1;
if y ~=b
naive([b,y],:) = naive([y,b],:);
end
for i = b+1:n
factor = naive(i,b)/naive(b,b);
naive(i,b:ok) = naive(i,b:ok) - factor*naive(b,b:ok);
end
end
naive


Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
%backward substitution
x = zeros(n,1);
x(n)=naive(n,ok)/naive(n,n);
for i = n-1:-1:1
x(i)=(naive(i,ok)-naive(i,i+1:n)*x(i+1:n))/naive(i,i);
end
end

Output
For 2 unknowns



















Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
For 3 unknowns











For 4 Unknowns

IV.


Name: Lourvic Ellisa F. Saba

Year: 4
th
yr.
Course Code:
ECEM428LAB

Activity #7 (Nave Gauss )

Date: 02/18/14
Score:
Observation/Conclusion:

Both of the Gauss Jordan and Nave Gauss Eliminations are tricky to manipulate in the
Matlab. As we can see, we need to put into consideration the number of unknowns in
each function than can probably use by the user. I need to find more functions in the
Matlab just in order to consider this need. The Backward substitution in the Nave Gauss
Elimination became tricky in my part. Above all, we can see that the methods used give
the same values. But the process they undergo are different. They have different way of
roots, one is by algebraic substitutions and the other are almost pure matric
manipulation. In order to have a better grasp in programming this methods, you need to
have larger scope of knowledge in the functions of Matlab to maximize the use of the
program and give better consideration for the Users.

Вам также может понравиться