diff --git a/midterm/midterm.m b/midterm/midterm.m new file mode 100644 index 0000000..7b48717 --- /dev/null +++ b/midterm/midterm.m @@ -0,0 +1,50 @@ +%% Midterm +% Name: Claudio Maggioni +% +% Date: 2020-04-02 +% +% This is a template file for the first assignment to get started with running +% and publishing code in Matlab. Each problem has its own section (delineated +% by |%%|) and can be run in isolation by clicking into the particular section +% and pressing |Ctrl| + |Enter| (evaluate current section). +% +% To generate a pdf for submission in your current directory, use the following +% three lines of code at the command window: +% +% >> options.format = 'pdf'; options.outputDir = pwd; publish('midterm.m', options) +% + +%% Problem 6 + +clear(); + +[L, U] = outerProductLU([1 1 1 1 1; + 2 4 4 4 4; + 3 7 10 10 10; + 4 10 16 20 20; + 5 13 22 30 35]); + +display(L); +display(U); + +[L, U] = outerProductLU([0 0 ; 0 0]); +display(L); +display(U); + +function [L,U] = outerProductLU(A) +dimensions = size(A); +n = dimensions(1); +L = zeros(n, n); +U = zeros(n, n); +for i = 1:n + if A(i, i) == 0 + disp("One of the pivots has become 0"); + L = []; + U = []; + break + end + L(:, i) = A(:, i) / A(i, i); + U(i, :) = A(i, :); + A = A - L(:, i) * U(i, :); +end +end \ No newline at end of file diff --git a/midterm/midterm.pdf b/midterm/midterm.pdf index 4bafd8c..a1e5f14 100644 Binary files a/midterm/midterm.pdf and b/midterm/midterm.pdf differ