A manufacturing company produces transistors, resistors, and computer chips. The company wants to use all available materials production for the weekly availability of copper, zinc, and glass. A system of equations can be made to find the maximum number of transistors, resistors, and computer chips the company can make. The units needed for each component and the units available in total can be found in the table above.
For the Numerical Method Matrix A and Matrix b were merged to create a new augmented matrix. With this new matrix, the coefficient can be derived by finding the identity matrix along the left side, also known as row reduced echelon form. This was done by row reducing along a diagonal set of pivot points. Once the lower and upper triangles are set to zero the solution for each component can be seen on the right.
Matlab's built-in backslash operator works the same as the numerical method. The code first finds the inverse of matrix A and then multiplies it with matrix b to solve for the coefficients.
[A] * [x]=[B] -> [A^-1] * [B]= [x]
Define parameters (set matrix a and b as augmented matrix)
Initialize vectors x and l. (to use for columns and rows in the matrix)
For loop (for determining which columns to use)
For loop (for determining which rows to use)
If statement ( to find the highest row value and move to the top of the matrix)
For loop for the first iteration (tell which column to use)
For loop initializing the first iteration (for row reduction using a factor)
For loop (for backward substitution)
b matrix divided by a matrix to represent coefficients
a = [4,3,2;1,3,1;2,1,3];
b = [960 510 610]';
%matrix are set for gauss
for k = 1:n-1 %loop for collumn
[maxval,index] = max(abs(a(k:n,k)));
swapindex = index + k -1;
if swapindex ~= k
a([k,swapindex],:)= a ([swapindex, k],:)
b([k,swapindex],:)= b ([swapindex, k],:)
end
for i = k + 1:n %loop for row
factor = a(i,k)/a(k,k); % factor ratio among
a(i,:) = a(i,:) - factor * a(k,:);
b(i) = b(i) - factor*b(k);
end
end
%back substitute
x = nan(length(n),1);
x(n) = b(n)/a(n,n);
for i = n-1:-1:1
% from n-1 to 1 by 1 interval
s = b(i);
for j = i + 1:n
s = s - a(i,j) * x(j);
end
x(j) = s / a(i,i);
end
The backslash operator had the exact numbers when getting to a solution. The gauss row reduction code yielded in the same results as using the backslash function.
The error can measured by how close the solution is for the numbers derived for each component. Seen above, each component was plugged back into each equation to make sure that B had remained the same. Since the total amount values matched with those given in the problem it can be assumed that it has no error.
The numerical method uses row reduction to find the solutions by finding an Identity matrix for the Augmented matrix of Matrices A and B. Whereas, the alternative approach finds the inverse of matrix A first to solve for x using the equation, [A^-1]*[B] = [x].
The condition number describes how likely the equations are to find a solution. Since the conditions number was relatively high, 5.3, the max amount of materials, [b], needed to be just right so that a solution could be found. If the total amounts, [b], change it is likely for the system to not have a viable solution.