wip midterm
This commit is contained in:
parent
1a4c732113
commit
5de5fc8df7
2 changed files with 50 additions and 0 deletions
50
midterm/midterm.m
Normal file
50
midterm/midterm.m
Normal file
|
@ -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
|
Binary file not shown.
Reference in a new issue