This repository has been archived on 2021-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
ICS/midterm/midterm.m
2020-04-03 00:09:45 +02:00

50 lines
No EOL
1.1 KiB
Matlab

%% 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