Matlab Activity 3
Matlab Activity 3
Group Number:
Leader:
Members:
A. Using MATLAB commands compute the following expressions if possible. Write the MATLAB SYNTAX
you used, and MATLAB out put on the space provided
A={1 2 0; 3 –1 2; -2 3 –2]
1 2 0
3 -1 2
-2 3 -2
X=
* * *
* * *
* * *
Explanation:
The answer is equal to 0, so the matrix is not invertible and singular. Therefore, matrix A is singular.
2. Determine the solution set of the give linear system below, using the method of (6 points each)
a. Inverse of Matrix
b. Gauss-Jordan Elimination
c. LU- factorization
J=[2 3 1; 3 3 1; 2 4 1]
2 3 1
3 3 1
2 4 1
K=[-1; 1; -2] K=
-1
-2
inv(J)*K ans =
-1
-2
Solution Set: (2, -1, -2)
MATLAB Syntax MATLAB Output
Gauss- Jordan Elimination M=
M=rref([J K]) 1 0 0 2
0 1 0 -1
0 0 1 -2
[L U P]=lu(J) 1 0 0
2/3 1 0
2/3 1/2 1
U=
3 3 1
0 2 1/3
0 0 1/6
P=
0 1 0
0 0 1
1 0 0
O=
O=rref([P'*L K])
1 0 0 1
0 1 0 -8/3
0 0 1 -1/3
N=
N=rref([U O(:,4)])
1 0 0 2
0 1 0 -1
0 0 1 -2
Solution Set: (2, -1, -2)
Which do you think among the three methods used is appropriate in the given system? Explain your
answer in 3 to 5 sentences. (5 points)
Among the three methods, the inverse method is the appropriate solution to this given system,
especially when using MATLAB. Since the system was a square matrix, it is also acceptable to use the
inverse of these equations. If the row and column are equal, it is recommended to use Gaussian-
Jordan rather than inverse or LU-Factorization, which can be employed depending on whether the
equation is singular or not if the row and column are equal.
B. For the following word problems, set up a system of linear equations then solve using matrices.
Verify your answer using MATLAB. Write the MATLAB syntax and MATLAB output on the space
provided (8 points each)
1. A mix of 1 lb almonds and 1.5 lbs cashews sells for 150.00 Php. A mix of 2 lbs almonds and 1 lb cashews
sells for 170.00 Php. How much does each nut cost per pound?
Set-Up of the System of Linear MATLAB Syntax MATLAB Output
Equation
X = Almonds R=[1 1.5; 2 1]; B=[150; 170]; Z=
Y = Cashews
X+1.5Y=150 W=rref(Z) W=
2X+Y=170
1.0000 0 52.5000
0 1.0000 65.0000
Final Answer: Almond’s cost P52.50 per pound, while cashews cost P65.00 per pound
2. Maria, Rebecca and Sally are selling baked goods for their math club. Maria sold 15 cookies, 20
brownies and 12 cupcakes and raised 2350.00 Php. Rebecca sold 22 cookies, 10 brownies and 11
cupcakes and raised 1985.00Php. Sally sold 16 cookies, 5 brownies and 8 cupcakes and raised
1330.00Php. How much did they charge for each type of baked good?
Set-Up of the System of Linear MATLAB Syntax MATLAB Output
Equation
15x+20y+12z=2350 H=[15 20 12; 22 10 11; 16 5 8]; ans =
S=[2350; 1985; 1330];
22x+10y+11z=1985
rref([H S])
16x+5y+8z=1330 1 0 0 30
0 1 0 50
x = Cookies 0 0 1 75
y = Brownies
z = Cupcakes
Final Answer: They charge cookies for 30 Php, brownies for 50 Php and 75 Php for cupcakes.