Open Educational Resources

Linear Systems of Equations: Problems

  1. Create a recursive function in Mathematica that calculates the determinant and compare it with the built-in determinant function. Test your function on matrices in \mathbb{M}^n for n=2,3,4,5,6, and 7.
  2. Use Cramer’s rule to solve the linear system of equations Ax=b defined as:

        \[ \left(\begin{matrix}1&2&3&7\\2&3&4&8\\-1&2&3&1\\4&5&6&1\end{matrix}\right)\left(\begin{array}{c}x_1\\x_2\\x_3\\x_4\end{array}\right)=\left(\begin{array}{c}3\\2\\4\\7\end{array}\right) \]

  3. Use the naive Gauss elimination method to solve the linear system of equations Ax=b defined as:

        \[ \left(\begin{matrix}1&2&3&7\\2&3&4&8\\-1&2&3&1\\4&5&6&1\end{matrix}\right)\left(\begin{array}{c}x_1\\x_2\\x_3\\x_4\end{array}\right)=\left(\begin{array}{c}3\\2\\4\\7\end{array}\right) \]

  4. Use the Cramer’s rule code, the naive Gauss elimination method code, and the Gauss-Jordan elimination method code given above to test how many “simple” equations the algorithm can solve in less than a minute for each method. You can do so by constructing the identity matrix of dimension n (using the command IdentityMatrix[n]) and a vector of values 1 of dimension n and then running the code. The solution to this should be \forall i:x_i=1. Repeat for higher values of n. If you surround your code with the command Timing[] it should give you an indication of how long the computations are taking. Draw the curve between the size of the system n and the timing taken by each method to find the solution. Is the relationship between the time taken to solve the system of equations and the size of the matrix linear or nonlinear?
  5. Repeat problem 4, however, in this case, use the commands:
    A = RandomReal[{-1, 1}, {n, n}];
    b = RandomReal[{-1, 1}, n];
    

     

    to generate a matrix A that is n\times n with random coefficients between -1 and 1 and a vector b with random numbers between -1 and 1. Does this affect the results of the time taken to solve the system as a function of the matrix size and the method used?

  6. Using random numbers similar to the previous problem, draw the curve showing the time taken to solve the system of equations as a function of the matrix size. Compare the LU decomposition, the naive Gauss elimination, and the Gauss-Jordan method. Try to optimize the code of the three methods and see if the generated curves are affected.
  7. Calculate the Cholesky Decomposition for the following positive definite symmetric matrix:

        \[ A= \left(\begin{matrix}6&15&55\\15&55&225\\55&225&979\end{matrix}\right) \]

  8. Calculate the Cholesky Decomposition for the following positive definite symmetric matrix:

        \[ A= \left(\begin{matrix}8&20&15\\20&80&50\\15&50&60\end{matrix}\right) \]

    Employ the results to find the solution to the system of equations:

        \[ Ax=b=\left(\begin{array}{c}50\\250\\100\end{array}\right) \]

  9. Find the LU factorization of the following matrix:

        \[ A=\left(\begin{matrix}10&2&-1\\-3&-6&2\\1&1&5 \end{matrix}\right) \]

    Employ the results to find two solutions for the vector x corresponding to the following two linear systems of equations:

        \[\begin{split} Ax&=b=\left(\begin{array}{c}12\\18\\-6\end{array}\right)\\ Ax&=b=\left(\begin{array}{c}27\\-61.5\\-21.5\end{array}\right) \end{split} \]

  10. Using the “Timing” keyword in Mathematica, compare the efficiency of the Cholesky Decomposition code provided above in comparison the built-in “CholeskyDecomposition” function in Mathematica by finding the decomposition for the identity matrix of size n. Can you produce a more efficient version of the provided code?
  11. Use the “CholeskyDecomposition” built-in function in Mathematica to produce a code to utilize the Cholesky Decomposition method to solve the linear system Ax=b when A is positive definite symmetric matrix. Compare with the Gauss elimination, the Gauss-Jordan elimination and the LU decomposition methods when solving the simple system of equations Ix=b where b is a vector whose components are all equal to 1. Similar to problem 4, draw the relationship showing the timing as a function of the size of the matrix n.
  12. Use Mathematica to program the Jacobi method such that the code would re-arrange the rows of the matrix A to ensure that the diagonal entries are all non-zero.
  13. Compare the Jacobi method and the Gauss elimination method to solve the simple system of equations Ix=b where b is a vector whose components are all equal to 5. Similar to problem 4, draw the relationship showing the timing as a function of the size of the matrix n. What do you notice about the Jacobi method in this case?
  14. Use the Gauss-Seidel method to find a solution to the following system after converting it into a diagonally dominant system:

        \[\begin{split} x_1+3x_2-x_3&=5\\ 3x_1-x_2&=5\\ x_2+2x_3&=1 \end{split} \]

  15. The following system is not diagonally dominant. Check whether the Jacobi and Gauss-Seidel methods converge or not using an initial guess of the zero vector.

        \[\begin{split} 4x_1+2x_2-2x_3&=0\\ x_1-3x_2-x_3&=7\\ 3x_1-x_2+4x_3&=5 \end{split} \]

  16. Assuming a stopping criterion of \varepsilon_s=0.000001, find the optimal value of \omega in the SOR method producing the fastest convergence in finding the solution to the following system. Compare with the Gauss-Seidel method.

        \[\begin{split} 4x_1+3x_2&=24\\ 3x_1+4x_2-x_3&=30\\ -x_2+4x_3&=-24 \end{split} \]

  17. Use the Gauss-Seidel method with \varepsilon_s=0.005 to solve the following system of linear equations:

        \[\begin{split} 15c_1-3c_2-c_3=3800\\ -3c_1+18c_2-6c_3=1200\\ -4c_1-c_2+12c_3=2350 \end{split} \]

  18. An electrical engineer supervises the production of three types of electrical components. Three kinds of material: metal, plastic, and rubber are required for production. The amounts needed to produce one unit of component 1 are 15 g of metal, 0.25 g of plastic, and 1.0 g of rubber. The amounts needed to produce one unit of component 2 are 17g of metal, 0.33g of plastic, and 1.2g of rubber. The amounts needed to produce one unit of component 3 are 19 g of metal, 0.42 g of plastic, and 1.6 g of rubber. If a total of 2.12, 0.0434, and 0.164 kg of metal, plastic, and rubber, respectively, are available each day. How many units of each component on average can be produced every day?
  19. Use the Gauss-Jordan elimination method to solve the following linear system of equations:

        \[ \begin{split} 120x_1-40x_2=637.65\\ -40x_1+110x_2-70x_3=735.75\\ -70x_2+170x_3-100x_4=588.60\\ -100x_3+120x_4-20x_5=735.75\\ -20x_4+20x_5=882.90 \end{split} \]

Leave a Reply

Your email address will not be published. Required fields are marked *