Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

ACTIVITY 3: ITERATIVE METHODS

OBJECTIVES
At the end of the activity, the students are expected to:
-use MATLAB to compute for the solutions for the linear equations.
-use MATLAB for computing repeatedly.

DISCUSSION
In this activity, we used MATLAB to solve for solutions to linear equations using Jacobi
method and Gauss-Seidel. These two methods can be used to find the solutions for
linear equation given the number of iterations. For the first part of the activity, given a
number riddle, we were asked to solve for the integers using Jacobi. For the second
part, a circuit is given and we were asked to solve for the current through each mesh.

PROCEDURE
A. Number Riddle
CODE
%Jacobi_Output
clc
disp('THE NUMBER RIDDLE')
disp('I have four integers A, B, C, and D ranging from -5 to 5.')
disp('Ten times A minus B plus two times of C is equal to six.')
disp('If I have A and C subtracted to eleven B and three D added together, the
result will be twenty-five.')
disp('Two times A plus ten times C is equal to negative eleven pluss the sum
of B and D.')
disp('If I have C subtracted to three times B plus 8 times D, the result will
be 15.')
disp('Find the four integers.')
S=1;
sol=input('Type "S" to show the solution.');
if sol==S;
disp('Given the following equations:')
disp('10A- B+ 2C
= 6')
disp(' -A-11B- C+3D= 25')

disp(' 2A- B+10C- D= 11')


disp('
3B- C+8D=15')

num=input('Enter number of iterations: ');


A=0;
B=0;
C=0;
D=0;
for x=1:num;
E=(B-(2*C)+6)/10;
F=(25+A+C-(3*D))/11;
G=(-11-(2*A)+B+D)/10;
H=(15-(3*B)+C)/8;
M=[A B C D];
A=E;
B=F;
C=G;
D=H;
end
disp(M)
end

OUTPUT

CONCLUSION
At the end of the activity, we were able to use MATLAB to manipulate our matrices. We
were able to use the basic operations and commands taught to us this semester for the
matrix manipulation. At the end of the activity, it was concluded that MATLAB has
several commands to manipulate vectors and matrices. It has commands that will allow

easier manipulation of matrix. Complicated operations are done in just a matter of


seconds.

You might also like