From 6ef85648821623931d24ff146b07e8392dec7618 Mon Sep 17 00:00:00 2001 From: Matthew Stuber <33096280+MatthewStuber@users.noreply.github.com> Date: Thu, 26 May 2022 16:58:17 -0400 Subject: [PATCH] Delete linear_solved.ipynb --- .../linear_solved.ipynb | 665 ------------------ 1 file changed, 665 deletions(-) delete mode 100644 tutorial/julia/Tutorial 1 - Linear Algebra/linear_solved.ipynb diff --git a/tutorial/julia/Tutorial 1 - Linear Algebra/linear_solved.ipynb b/tutorial/julia/Tutorial 1 - Linear Algebra/linear_solved.ipynb deleted file mode 100644 index 4e5f900..0000000 --- a/tutorial/julia/Tutorial 1 - Linear Algebra/linear_solved.ipynb +++ /dev/null @@ -1,665 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Linear Algebraic Systems \n", - "\n", - "*Supplemental material for Chapters 2 of \"Numerical Methods and Chemical Engineering Applications\" by Dorfman and Daoutidis.*\n", - "\n", - "
\n", - "\n", - "# Learning Objectives \n", - "\n", - "### *Setting up a linear system*\n", - "- Be able to distinguish a linear system from a nonlinear system.\n", - "- Learn to write a linear system in a matrix-vector format.\n", - "- Input a linear system into a program\n", - "- Write applicable engineering models in a linear format.\n", - "\n", - "### *Characterizing linear systems*\n", - "- Determine the bandwidth(s) of the linear system.*\n", - "- Determine if a linear system has a unique solution.\n", - "- Will solving a linear system provide a meaningful result (is it well-posed).\n", - "\n", - "### *Solving a linear system*\n", - "- Solve a linear system by Gauss-Elimination\n", - "- Solve a linear system by LU factorizations.\n", - "- State when numerical errors occur may occur in Gauss-Elimination and how to resolve them.\\*\n", - "- Be able to state some conditions for the convergence of Jacobi and Gauss-Siedel methods.\\*\n", - "\n", - "\\*Not covered in tutorial.\n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Relevance \n", - "\n", - "It would be only a slight overstatement to say that linear algebra underlies all modern numerical algorithms to one degree or another. Even software which specifically addresses nonlinear or complicated forms will often make use of linear algebra in a myriad of subroutines. In essence, many complicated problems can be reduced to repeated formulating and solving linear systems. \n", - "\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Chlorination of Benzene \n", - "\n", - "Monochlorobenzene is a high boiling point solvent used in many industrial applications ranging from the manufacture of [dyes](https://patentimages.storage.googleapis.com/76/55/12/31756682f755c5/US6013811.pdf), [plastic and rubber processing](https://patentimages.storage.googleapis.com/66/c8/e1/69918f557fbd35/US8563079.pdf), [paints](https://patentimages.storage.googleapis.com/28/17/a7/a40e46f75806cf/US9062206.pdf), and [waxes](https://patents.google.com/patent/US3999960A/en). Approximately, [$1 billion](https://www.prnewswire.com/news-releases/global-chlorobenzene-industry-300939916.html) worth of this solvent are used per year. It is [produced by combining chlorine with benzene](https://onlinelibrary.wiley.com/doi/abs/10.1002/14356007.o06_o03) in the presence of a Lewis acid catalyst such as Ferric Chloride FeCl3 or Anhydrous Aluminum Chloride AlCl3. When benzene and chlorine are mixed two key reactions occur: (1) the chlorination of benzene and (2) the secondary undesirable chlorination of the resulting monochlorobenzene. Product purity is ensured by performing a series of separation steps after the initial reaction and reagant usage is reduced by including a recycle loop. \n", - "\n", - "
\n", - "Objective: A large customer order has been placed for monochlorobenzene that needs to be fulfilled on a tight timeline. The small chemical company you work for has occasionally produced this solvent in the past and has an existing 6m3 continuously stirred tank reactor (CSTR) that will need to be repurposed to produce 25kmol/h monochlorobenzene. Moreover, there isn't sufficient development time available to attempt to improve the processing conditions for the reactor or separators. As a result, you'll need to use the documented process conditions for the reactor and separators which means supplying to the first separator an effluent consisting of 90% benzene, 7% monochlorobenzene, and 3% dichlorobenzene by mole. We need to determine the recycle flow rates and reaction rates required needed to achieve the desired rate at which monochlorobenzene need to be produced. \n", - "
\n", - "\n", - "Denote benzene as (A), monochlorobenzene as (B), and dichlorobenzene as (C). The mole fraction of species A in stream S1 is denote by y1,A and the molar flowrate F [kmol/h] for stream S1 is denoted F1.\n", - "\n", - "- The feed stream is composed entirely of A and Cl2.\n", - "- An excess amount of Cl2 is provided and HCl removal can be assumed to be trivial. So it's reasonable exclude it from our design considerations. Moreover, this means the reactions which take place in the reactor vessel can be simplified to AB (at rate r1 [kmol/h]) and BC (at rate r2 [kmol/h]).\n", - "\n", - "\n", - "\n", - "# Variables and Mass Balances \n", - "\n", - "For streams containing only a pure substance, we need only keep track of the total flow rate. Enumerating each quantity in the model is given by $F_1$, $F_2$, $F_3$, $F_4$, $F_5$, $F_6$, $F_7$, $y_{3,A}$, $y_{3,B}$, $y_{3,C}$, $y_{4,B}$, $y_{4,C}$, $r_1$, $r_2$, and $\\nu$. Five of these are specified (e.g. these are **parameters** with fixed values). This leaves ten degrees of freedom associated with a variable. We'll now need to write out the equations which govern the system (physical laws, equipment specifications, and performance specifications). We'll start with writing the mass balances over each unit operation. \n", - "\n", - "Mixer (Overall Mass Balance): \n", - "\n", - "\\begin{align}\n", - " F_1 + F_7 - F_2 &= 0\n", - "\\end{align}\n", - "\n", - "Reactor (Individual Component Mass Balances):\n", - "\n", - "\\begin{align}\n", - " F_2 - r_1\\nu - y_{3,A}F_3 &= 0 \\\\\n", - " (r_1 - r_2)\\nu + y_{3,B}F_3 &= 0 \\\\\n", - " r_2\\nu - y_{3,C}F_3 &= 0\n", - "\\end{align}\n", - "\n", - "Separator #1 (Individual Component Mass Balances):\n", - "\n", - "\\begin{align}\n", - " F_3 - F_4 - F_7 &= 0 \\\\\n", - " y_{3,B}F_3 - y_{4,B}F_4 &= 0 \\\\\n", - " y_{3,C}F_3 - y_{4,C}F_4 &= 0\n", - "\\end{align}\n", - "\n", - "Separator #2 (Individual Component Mass Balances):\n", - "\n", - "\\begin{align}\n", - " F_4 - F_5 - F_6 &= 0 \\\\\n", - " y_{4,B}F_4 - F_5 &= 0\n", - "\\end{align}\n", - "\n", - "In order to write these equations in a matrix-vector form: we'll first need to associate each variable (excluding **parameters**) in the model with a component in a vector of variables, $\\mathbf{x}$. \n", - "\n", - "\\begin{align}\n", - " \\mathbf{x} = (F_1, F_2, F_3, F_4, F_6, F_7, y_{4,B}, y_{4,C}, r_1, r_2)\n", - "\\end{align}\n", - "\n", - "So, $x_2 = F_2$, $x_3 = F_3$ and so on until we have $x_{10} = r_2$. \n", - "\n", - "
\n", - "Now, take a minute to inspect the model and categorize the system of equations. \n", - "
\n", - "\n", - "The 2nd and 3rd equations for Separator #1 as well as the 2nd equation in Separator #2 contain the expressions $y_{4,B}F_4$ and $y_{4,C}F_4$. These terms consist of two variables being multiplied by one another (a bilinear term) which is one of simplest commonly encountered nonlinear term. All other expressions consist of addition, subtraction, and the multiplication of a parameter by a variable. So this system of equations is nonlinear but would be linear if we ommitted the expressions: $y_{4,B}F_4$ and $y_{4,C}F_4$.\n", - "\n", - "
\n", - "It's often useful to reformulate a model (algebraicly rearrange and potentially introduce new variables) to arrive at a more easily solvable form. \n", - "
\n", - "\n", - "We'll start by introducing two new variables: the molar flowrates $F_{4,B}$ and $F_{4,C}$ defined as by\n", - "\n", - "\\begin{align}\n", - " F_{4,B} = y_{4,B}F_4 \\\\\n", - " F_{4,C} = y_{4,C}F_4\n", - "\\end{align}\n", - "\n", - "We can then write an additional equation for the molar flowrates of S4:\n", - "\n", - "Molar flowrate expressions for S4:\n", - "\n", - "\\begin{align}\n", - " F_{4,B} + F_{4,C} &= F_4\n", - "\\end{align}\n", - "\n", - "Next, we'll introduce the variables: $F_{3,A}$, $F_{3,B}$, and $F_{3,C}$ defined as:\n", - "\n", - "\\begin{align}\n", - " F_{3,A} = y_{3,A}F_3 \\\\\n", - " F_{3,B} = y_{3,B}F_3 \\\\\n", - " F_{3,C} = y_{3,C}F_3\n", - "\\end{align}\n", - "\n", - "We can then write an additional equation for the molar flowrates of S3:\n", - "\n", - "Molar flowrate expressions for S3:\n", - "\n", - "\\begin{align}\n", - "F_{3,A} + F_{3,B} + F_{3,C} = F_3\n", - "\\end{align}\n", - "\n", - "We can then rearrange the mass balances for the Reactor, Separator #1, and Separator #2.\n", - "\n", - "Reactor (Individual Component Mass Balances):\n", - "\n", - "\\begin{align}\n", - " F_2 - r_1\\nu - F_{3,A} &= 0 \\\\\n", - " (r_1 - r_2)\\nu + F_{3,B} &= 0 \\\\\n", - " r_2\\nu - F_{3,C} &= 0\n", - "\\end{align}\n", - "\n", - "Reformulated Separator #1 Mass Balances:\n", - "\n", - "\\begin{align}\n", - " F_3 - F_4 - F_7 &= 0 \\\\\n", - " F_{3,B} - F_{4,B} &= 0 \\\\\n", - " F_{3,C} - F_{4,C} &= 0\n", - "\\end{align}\n", - "\n", - "Reformulated Separator #2 Mass Balances:\n", - "\n", - "\\begin{align}\n", - " F_4 - F_5 - F_6 &= 0 \\\\\n", - " F_{4,B} - F_5 &= 0\n", - "\\end{align}\n", - "\n", - "\\begin{align}\n", - " \\mathbf{x'} = (F_1, F_2, F_{3,A}, F_{3,B}, F_{3,C}, F_3, F_{4,B}, F_{4,C}, F_4, F_6, F_7, r_1, r_2)\n", - "\\end{align}\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "INTERACTIVE! Now we enter the above linear equation, Mx' = b in matrix-vector form.\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "-0.07" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Define the Mx' = b linear system\n", - "\n", - "\n", - "# Define storage for linear system\n", - "M = zeros(13,13) # Makes an 2d array of size 13-by-13. This array has 13 rows and 13 columns.\n", - "b = zeros(13) # Makes a column vector of size 10. A vector with 13 rows and 1 column.\n", - "\n", - "# Input parameters\n", - "y3A = 0.90 # effluent benzene concentration of reactor\n", - "y3B = 0.07 # effluent monochlorobenzene concentration of reactor\n", - "y3C = 0.03 # effluent dichlorobenzene concentration of reactor\n", - "V = 6 # reactor volume\n", - "F_5 = 25.0 # flow rate of monochlorobenzene required\n", - "\n", - "### MASS BALANCE (MIXER) ###\n", - "\n", - "# fills in the first row\n", - "M[1,1] = 1.0 # Set the matrix M's entry in the first row and second column to 1\n", - "M[1,2] = -1.0 # Set the matrix M's entry in the first row and second column to -1\n", - "M[1,11] = 1.0 # Set the matrix M's entry in the first row and eighth column to 1\n", - "\n", - "# b[1] and all other entries of M in row #1, so no need to change these values\n", - "\n", - "### REACTOR MASS BALANCES ###\n", - "\n", - "# reactor - equation #1\n", - "M[2,2] = 1.0 \n", - "M[2,3] = -1.0\n", - "M[2,12] = -V\n", - "\n", - "# reactor - equation #2\n", - "M[3,4] = 1.0 \n", - "M[3,12] = -V\n", - "M[3,13] = V\n", - "\n", - "# reactor - equation #3\n", - "M[4,5] = -1.0 \n", - "M[4,13] = V\n", - "\n", - "### SEPARATOR #1 - MASS BALANCES ###\n", - "\n", - "# separator #1 - equation #1\n", - "M[5,6] = 1.0\n", - "M[5,9] = -1.0\n", - "M[5,11] = -1.0\n", - "\n", - "# separator #1 - equation #2\n", - "M[6,4] = 1.0\n", - "M[6,7] = -1.0\n", - "\n", - "# separator #1 - equation #3\n", - "M[7,5] = 1.0\n", - "M[7,8] = -1.0\n", - "\n", - "### SEPARATOR #2 - MASS BALANCES ###\n", - "\n", - "# equation #1\n", - "M[8,9] = 1.0 \n", - "M[8,10] = -1.0 \n", - "b[8] = F_5\n", - "\n", - "# equation #2\n", - "M[9,8] = 1.0 \n", - "b[9] = F_5\n", - "\n", - "### MOLAR FLOWRATE EXPRESSIONs ###\n", - "M[10,8] = 1.0 \n", - "M[10,9] = -1.0\n", - "M[10,7] = 1.0\n", - "\n", - "M[11,3] = 1.0 \n", - "M[11,4] = 1.0\n", - "M[11,5] = 1.0\n", - "M[11,6] = -1.0\n", - "\n", - "M[12,3] = 1.0\n", - "M[12,6] = -y3A\n", - "\n", - "M[13,4] = 1.0\n", - "M[13,6] = -y3B\n" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "\"This Matrix (M) is \"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "13×13 Array{Float64,2}:\n", - " 1.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0\n", - " 0.0 1.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -6.0 0.0\n", - " 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 -6.0 6.0\n", - " 0.0 0.0 0.0 0.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 6.0\n", - " 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 -1.0 0.0 -1.0 0.0 0.0\n", - " 0.0 0.0 0.0 1.0 0.0 0.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0\n", - " 0.0 0.0 0.0 0.0 1.0 0.0 0.0 -1.0 0.0 0.0 0.0 0.0 0.0\n", - " 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 -1.0 0.0 0.0 0.0\n", - " 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0\n", - " 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 -1.0 0.0 0.0 0.0 0.0\n", - " 0.0 0.0 1.0 1.0 1.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n", - " 0.0 0.0 1.0 0.0 0.0 -0.9 0.0 0.0 0.0 0.0 0.0 0.0 0.0\n", - " 0.0 0.0 0.0 1.0 0.0 -0.07 0.0 0.0 0.0 0.0 0.0 0.0 0.0" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "\"The r.h.s vector (b) is \"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "13-element Array{Float64,1}:\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 25.0\n", - " 25.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "13-element Array{Float64,1}:\n", - " 83.33333333333337 \n", - " 833.3333333333339 \n", - " 750.0000000000006 \n", - " 58.33333333333337 \n", - " 25.0 \n", - " 833.3333333333339 \n", - " 58.33333333333337 \n", - " 25.0 \n", - " 83.33333333333337 \n", - " 58.33333333333337 \n", - " 750.0000000000006 \n", - " 13.888888888888896\n", - " 4.166666666666667" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# Run this to display the input matrix and vector\n", - "display(\"This Matrix (M) is \") \n", - "display(M)\n", - "display(\"The r.h.s vector (b) is \") \n", - "display(b)\n", - "x = M\\b\n", - "display(x)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Existence and Uniqueness of the Solution \n", - "\n", - "Now that the linear system has been formulated, let's check to see whether the system has a solution. For a square matrix M, M system is invertible\n", - "\n", - "
\n", - " INTERACTIVE! Make use of the function det to check see if matrix M is invertible. Does the linear equation Mx = b have a unique solution? \n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "-1.0799999999999992" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "using LinearAlgebra: det\n", - "\n", - "# FILL IN THE REST BELOW HERE\n", - "det(M)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Well-posed problems and the Condition Number \n", - "\n", - "While a linear system, `Mx = b`, may have a unique solution, we also seek to understand whether using a particular algorithm to solve `Mx = b` will yeild an accurate solution. We often don't know `M` or `b` exactly. As a consequence, solutions which vary greatly when `M` or `b` are slightly perturbed may be suspect. This is generally assessed by evaluating the **condition number** of a linear system and is defined as: $\\text{cond}(M) \\equiv ||M|| \\times ||M^{-1}||$. A derivation of this is given in section 2.3.4 of Dorfman and Daoutidis, Numerical Methods with Chemical Engineering Applications which arrives at the following inequality:\n", - "\n", - "$||\\Delta x || \\leq \\text{cond}(M)\\bigg(\\frac{|| \\Delta b || || x ||}{|| b ||}\\bigg)$\n", - "\n", - "For a fixed condition number, $\\text{cond}(M)$, solution $x$, and $b$ if we slightly perturb $b$ by $\\Delta b$ then $x$ may change by at most an amount proportional to the condition number. Another way of interpreting this is by applying the following rule of thumb: the condition number $\\kappa$ means that the method looses $\\log_{10}{\\kappa}$ of accuracy relative to rounding error.\n", - "\n", - "If an application leads to an ill-posed problem (values of **M** and **b** may be known to very high precision), there are a multitude of ways this may be dealt with. This most common and often most robust approach is to apply a [**preconditioner**](http://www.mathcs.emory.edu/~benzi/Web_papers/survey.pdf). That is we find an appropriate matrix **Y** and multiply both sides of the original linear system to create an equivalent new linear system, `(YM)x = (Yb)`, which has a lower condition number. We can then solve the equivalent modified system. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "INTERACTIVE! Make use of the function cond to compute the condition number using the $L^2$-norm. Is the matrix A well-conditioned? \n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1494.7023893088221" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "using LinearAlgebra: cond\n", - "\n", - "# FILL IN THE REST BELOW HERE\n", - "cond(M)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Solving the linear equation with Gauss Elimination " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now let's write a quick script to solve Mx = b. We'll do this in three steps. Defining a function to perform forward elimination, a function to back substitution, and lastly a main function to perform each of the prior functions in sequence." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "function forward_elimination!(M,b,n)\n", - " \n", - " for k = 1:(n - 1)\n", - " for i = (k + 1):n\n", - " m = M[i,k]/M[k,k]\n", - " for j = (k + 1):n\n", - " M[i,j] = M[i,j] - m*M[k,j]\n", - " end\n", - " b[i] = b[i] - m*b[k]\n", - " end\n", - " end\n", - " \n", - " return nothing\n", - "end" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "Comment: Note that while M, b are used in prior cells these variables don't interfere in the definition of forward_elimination!. The variables listed in the argument of forward_elimination!, that is (M,x,b,n), are evaluated in local scope when forward_elimination! is called.\n", - "
" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "INTERACTIVE! The overall gauss elimination function is defined below. You just need to finish coding the back_substitution! function.\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "function back_substitution!(M,x,b,n)\n", - " \n", - " # FILL IN THE REST BELOW HERE\n", - " \n", - " return nothing\n", - "end" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "ename": "UndefVarError", - "evalue": "UndefVarError: M not defined", - "output_type": "error", - "traceback": [ - "UndefVarError: M not defined", - "", - "Stacktrace:", - " [1] top-level scope at In[2]:10" - ] - } - ], - "source": [ - "function Gauss_Elimination!(M, b)\n", - " n = length(b)\n", - " x = zeros(n)\n", - " \n", - " forward_elimination!(M,b,n)\n", - " back_substitution!(M,x,b,n) \n", - " \n", - " return x\n", - "end\n", - "\n", - "# Runs a Gauss elimination routine using Mx = b has inputs\n", - "x = Gauss_Elimination!(M, b)\n", - "\n", - "display(\"The solution via Gauss elimination is \"); \n", - "display(x)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Solving with an LU factorization \n", - "\n", - "
\n", - "INTERACTIVE! Run the following snippet of code to solve the linear system using LU factorization to solve the linear system.\n", - "
" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "\"The solution via LU factorization is \"" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/plain": [ - "13-element Array{Float64,1}:\n", - " 83.33333333333337 \n", - " 833.3333333333339 \n", - " 750.0000000000006 \n", - " 58.33333333333337 \n", - " 24.999999999999996\n", - " 833.3333333333339 \n", - " 58.33333333333337 \n", - " 25.0 \n", - " 83.33333333333337 \n", - " 58.33333333333337 \n", - " 750.0000000000006 \n", - " 13.888888888888896\n", - " 4.166666666666666" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "using LinearAlgebra: lu\n", - "\n", - "lu_fact = lu(M) # performs an LU factorization of M. Note that pivot = Val(false)\n", - " # means that the LU factorization is performed without pivoting\n", - " # (otherwise a permutation matrix describing the pivots is computed as well)\n", - "\n", - "y = lu_fact.L\\b # solve Ly = b for y\n", - "x = lu_fact.U\\y # solve Ux = y for x\n", - "\n", - "display(\"The solution via LU factorization is \"); \n", - "display(x)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "
\n", - "\n", - "# Questions for reflection \n", - "\n", - "- What varieties of problems may result in a banded matrix?\n", - "- What does it mean that an iterative method converged? \n", - "- When is an absolute or relative convergence criteria preferable?\n", - "- When is solving by one method versus another preferable (e.g. Banded Gauss-Elimination versus Gauss-Siedel)?" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Julia 1.3.1", - "language": "julia", - "name": "julia-1.3" - }, - "language_info": { - "file_extension": ".jl", - "mimetype": "application/julia", - "name": "julia", - "version": "1.3.1" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -}