First, the values given in the problem were rewritten in matrix notation and as a system of equations modeling the production run. The analytical solution was found using the backslash solver which is a built-in MATLAB command for solving a system of equations. Given the weekly total amount of copper, zinc, and glass available, 120 transistors, 100 resistors, and 90 computer chips will be manufactured this week. The problem setup and solution is shown below.
In MATLAB, Gauss Elimination with partial pivoting was employed to solve the system of equations. The results of the numerical method are shown below.
Forward elimination for the first column and the subsequent back substitution is shown. In a complete calculation, forward elimination would be completed for each row before using back substitution so that the solutions can be easily found.
In addition to using Gauss Elimination with partial pivoting, the system was solved by hand using the Gauss-Seidel Method. This iterative approach starts with an initial guess and then systematically improves the estimate of the solution. After each iteration, the error between the current estimate and the last estimate is calculated. In real-world scenarios, there would be an error criteria that the solution must satisfy but in this problem, four iterations of the Gauss-Seidel Method are calculated. After just four iterations, the relative percent error of the number of transistors, resistors, and computer chips is less than 10%. Carrying out more iterations will increase the accuracy.
True error between the analytical solution and the numerical solution was calculated in MATLAB using the following formula.
To confirm the true error between the analytical and numerical solution, the "format long" command was used. After using more significant digits, the true error remained the same.
Next, the system was checked for ill-conditioning. Using the inverse of [A], three methods for determining whether the system is ill-conditioned were performed. The first method requires that matrix [A] be scaled such that the highest value in each row is 1. If the inverse of this scaled matrix has values that are much greater than 1, then the system is ill-conditioned. Secondly, if the product of the inverse of the original [A] matrix and A is not the identity matrix, the system is ill-conditioned. The third method for checking ill-conditioning is taking the inverse of the inverse of [A]. This should yield the original [A]. If not, the system is ill-conditioned. All three methods do not indicate that the system is ill-conditioned.
Lastly, the condition number of the system was calculated using MATLAB. A condition number is a measure of the change in the output of a system given proportional to the input. Greater condition numbers indicate that more precision in the system is lost and the system is likely ill-conditioned. In this system, the small condition number of 8.5263 is consistent with the previous conditioning methods, indicating that the system is well-conditioned.
Gauss elimination with partial pivoting accurately solved the system of equations to provide the correct number of transistors, resistors, and computer chips. The absolute true error between the solution found using Gauss elimination with partial pivoting and MATLAB's backslash solver was zero. The high accuracy can be attributed to partial pivoting. Partial pivoting avoids division by zero, minimizes round-off error, and improves ill-conditioning if present. Gauss elimination without partial pivoting should not be employed to solve a complex system of equations due to these advantages.
The condition number of a system should always be calculated to provide an indication of the conditioning. An ill-conditioned system of linear equations occurs when one or more of the equations have similar or the same slope. In this case, the intersection of the lines, or the solution, is difficult or impossible to pinpoint. On the contrary, well-conditioned systems have equations with dissimilar slopes. After using a numerical approach for solving a system of equations, finding the condition number is an important tool that can provide an explanation to the inaccuracy of the solution.
The problem was setup by hand. The Taylor series expansion can be used to derive numerical estimates of higher order derivatives that are called finite difference approximations. Centered different approximations were used in this problem, because they are typically more accurate than forward or backward approximations.
After the system of equations was found, the system was written in matrix notation in MATLAB to find the analytical and numerical solutions.
The backslash solver was used to analytical solve this system of equations for the concentration of the chemical. Then, the values for c(0) and c(10) were included to get the entire solution set. Even though the following solution is the analytical solution, there is still a small amount of round-off error due to MATLAB's limited storage space of each value.
The analytical solution, which represents the concentration of the chemical over the distance interval, was plotted to determine trends as distance along the canal is changed. The plot is shown below.
Figure 1: The concentration of the chemical over distance is shown in the plot.
According to the analytical solution and Figure 1, the concentration of the chemical is decreasing as distance is increasing. The slope along each successive step is closer to zero. Given a further distance in the canal, the slope and the concentration may level off at zero.
Like in Problem 1, Gauss elimination with partial pivoting was employed to find the numerical solution to the system of equations. The MATLAB results are following.
The MATLAB Code section below shows the exact code that was used to obtain the solution. Notice that the numerical solution is identical to the analytical solution, indicating the effectiveness of Gauss elimination with partial pivoting.
Forward elimination for the first column and the subsequent back substitution is shown in the following sample calculation. In a complete calculation, forward elimination would be completed for each row before using back substitution so that the solutions can be easily found. This sample is intended to show the idea behind Gauss elimination with partial pivoting.
The error between the analytical and numerical solutions was found using an absolute true error calculation. Since both solutions were the exact same to all the significant digits stored in MATLAB, the absolute true error is a column vector of zeros. The calculation is shown below.
The conditioning of the system of equations was also determined by first calculating the condition number in MATLAB.
cond (A) = 6.0492
Then, the system was checked for ill-conditioning using the same methods as in Problem 1. All three methods failed to show ill-conditioning, as indicated in the MATLAB code below. These methods support the small condition number in concluding that the system of equations is well-conditioned. The three methods are outlined below.
The given second order differential equation represents a chemical that is diffusing through a one-dimensional canal. Since it results from a steady state mass balance, I would expect the concentration to be decreasing and approaching a constant value. In other words, I would expect the slope to be approaching zero as distance increases. Figure 1 confirms my hypothesis. The results and plot show that the concentration is highest initially and decreases as distance increases.
Just like in Problem 1, Gauss elimination with partial pivoting accurately solved the system of equations to provide the correct concentration along the canal. The absolute true error between the solution found using Gauss elimination with partial pivoting and MATLAB's backslash solver was zero, proving the effectiveness Gauss elimination with partial pivoting. The high accuracy can partially be attributed to the partial pivoting. Partial pivoting avoids division by zero, minimizes round-off error, and improves ill-conditioning if present. Gauss elimination without partial pivoting should not be employed to solve a complex system of equations due to these advantages.
The condition number provides the condition or "error" within the system. A condition number indicates the change in the output of a system given a small change in the input. All condition numbers are greater than 1, and the condition number of this system is 6.0492. This small value signifies that the system is well-conditioned. The equations in a well-conditioned system have widely differing slopes so that it is easy to find the point of intersection or solution. Conversely, in an ill-conditioned system, the intersection between equations would be difficult to discover because of similar slopes of the equations. Since this problem is well-conditioned, the solution is likely very accurate.
a)
The peer review process was beneficial for me to understand another perspective on how to solve the problem and receive feedback on how to improve my solution. I first modified my initial submission using the peer review feedback. Initially, I didn't realize that Figure 1 was too large to fit on the screen so I decreased it's size immediately. I also moved the Pseudocode sections for both problems right before the respective MATLAB code sections. Then, I decreased the font size of the pseudocode per my partner's suggestions. Lastly, to make the code and pseudocode easier to read, I included more spaces to separate sections. Overall, the peer review comments were very helpful in pointing out formatting improvements.
b)
From reviewing my partner's code, I learned two main things. First, I learned that code is much easier to read when there is adequate spacing between different sections and functions. This is why I decided to include more spaces in my code. Secondly, I learned that creating the full code within various functions makes it very easy to perform the same function on a new system. I will take this into account when working on future problems in MATLAB, especially when the same method needs to be applied to many systems. If written correctly, it will be faster to solve systems but it also will be more challenging to troubleshoot if it fails.
c)
From the initial submission, I made several changes after looking at my peer review comments and my initial submission rubric. The most dramatic change made was moving the backslash solver to the analytical solution and solving the system using a numerical method in problem 2. I solved it using Gauss elimination with partial pivoting and changed the pseudocode to reflect this. I also included sample calculations for both numerical solutions to show the reader how Gauss elimation with partial pivoting is done by hand. Then, with an analytical and numerical solution, I included an absolute true error calculation to determine the error using Gauss elimination with partial pivoting. I also changed the title and corresponding explanation of the plot from problem 2 to showcase concentration over distance rather than concentration over time. Additionally, I corrected the condition number calculation from problem 1 to use the original coefficient matrix.