In this final assignment we will make use of two very important concepts: Lower/Upper triangularization, and solving a system of equations using the decomposed matrix.
MATLAB has the built-in function called lu() which will decompose a matrix A into an upper and a lower triangular matrix. But it will do so by swapping rows. We must keep track of the row swaps in order to solve our system.
Your custom function will do the same thing as the lu() function, but will not support row swaps. We will be making use of the THIRD kind of elementary row operation: adding a scalar multiple of one row to another.
You will create a function called ludecomp() which takes in one input, and returns two outputs. The only input is the matrix you are trying to decompose. The first output is the lower triangular matrix (a square matrix) and an upper triangular matrix (a matrix of the same size as the input).
This type of decomposition only works when the number of rows of the input matrix is less than or equal to the number of columns of the input matrix. If the matrix has dimension nxm where n > m, then this decomposition does not work. If that is the case, print an error to the user.
After you create this, you will create a script file called which will solve a simple linear system using the ludecomp() function.
Part 1: Setting up my Lower and Upper
The upper triangular matrix should be the same matrix as the input matrix. The lower triangular matrix must start off as a square identity matrix. Use matrix multiplication rules to determine the size of the lower triangular matrix given the following equation:
Part 2: Decompose
𝐿𝑈 = 𝐴
Now that we have our matrices, we will create U and L together. This step requires a loop. It should loop the number of rows of A.
1. Start at column 1. We are trying to change values under the (1,1) element in the same column to be 0.
2. Create the dividing factor
a. This value is unique to each row below row 1. Using the upper triangular matrix U, for row 2 in U, the dividing factor is:
𝑓 = -𝑈(2,1) / 𝑈(1,1)
3. Perform the elementary row operation on U by multiplying the first row by the factor, and adding it to the second row
4. Create a temporary identity matrix, the same size as L
5. Perform the same elementary row operation in Step 3, except on the temporary identity matrix
6. Set the new value of L to be the old value of L multiplied by the inverse of the temporary identity matrix.
7. Repeat Step 2 – 6 for the remaining rows, calculating a new dividing factor, and performing the elementary row operations on U
8. Repeat steps 1 – 7 for the remaining columns.
Part 3: Solving the System
We will now make use of the LU decomposition function we created. Create a script file that solves this problem:
Consider an open economy with three industries: coal-mining operation, electricity-generating plant and an auto-manufacturing plant. To produce $1 of coal, the mining operation must purchase $0.1 of its own production, $0.30 of electricity and $0.1 worth of automobile for its transportation. To produce $1 of electricity, it takes $0.25 of coal, $0.4 of electricity and $0.15 of automobile. Finally, to produce $1 worth of automobile, the auto-manufacturing plant must purchase $0.2 of coal, $0.5 of electricity and consume $0.1 of automobile. Assume also that during a period of one week, the economy has an exterior demand of $50,000 worth of coal, $75,000 worth of electricity, and $125,000 worth of autos.
Find the production level of each of the three industries in that period of one week in order to exactly satisfy both the internal and the external demands.
To help guide you, imagine the system to be this one:
𝐴𝑃 = 𝑑
In this system, the vector d is the external demand. The vector P is the production level of each industry, and A is the coefficient matrix that describes how much each industry contributes, or consumes, to the overall external demand of the industry. For example:
The coal industry contributes $0.9 to the external coal demand, the electricity industry contributes
-$0.25 to the external coal demand, and the automobile industry contributes -$0.20 to the external coal demand.
Use the LU decomposition function to solve. Output your results to the command window for each industry. To check your answer, it must satisfy the original system, no sample output will be given.
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.function X=lusolve(L,U,B)
%Back-Substitution for L
%Back-Substitution for U
By purchasing this solution you'll be able to access the following files: