# Gauss Elimination

**Direct Methods and Least Squares**

**Solution**** **

# Computing the determinant:

The command in shown below has been used to generate an upper triangular matrix U with 0.1 in the diagonal and random values in the upper triangle.

## Command set 1

U = round(100*rand(10));

U = triu(U,1)+0.1*eye(10);

After defining this matrix, we find det(U), det(U^{T}) and det(UU^{T}) using MATLAB.

det(U) = 1e-10

det(U^{T}) = 5.90333474942096e-10

det(UU^{T}) = 2129381193.41908

The condition number of U found by using the command shown below:

cond(U,1)

The condition number of U was found to be 3.93125887961686e+26

Ill-conditioned matrix:

The matrix A is generated using the following piece of code:

## Command set 2

A = eye(n)-triu(ones(n),1);

The condition number of A for different ‘n’ is generated and then plotted against ‘n’ as shown below:

Here, 1/eps is equal to 4.5035996273705e+15. For n = 48, condition number exceeds 1/eps.

Pivots are diagonals of upper triangular matrix which is 1 in this case.

For n = 53, determinant of A is non-zero i.e. 1, which represents that the matrix is non-singular. The norm of x is 2.60015445718465e+15, while the norm of b is 1. This suggests that x vector is much greater than b which is suggesting poor conditioning.

**Least squares:**

The data from .dat file is loaded using “Import data” option in MATLAB according to given specification.

The time data in VarName1 is converted to datenum and then plotted by using following piece of code:

day = datenum(VarName1,’yyyymmdd’);
t = day-day(1); temp = VarName2; figure; plot(t, temp); xlabel(‘Days (Starting from 1^{st} Jan. 1995)’); ylabel(‘Temperature (F)’); title(‘Historical temperature data’); xlim([0 t(end)-1]); grid on; figure; plot(t(1:730), temp(1:730)); xlabel(‘Days (Starting from 1^{st} Jan. 1995)’); ylabel(‘Temperature (F)’); title(‘Historical temperature data (2-year data)’); xlim([0 729]); grid on; |

Finally, with the given model curve fitting over given data to find average temperature c1 and trend c2.

The average temperature was found to be 52.74 Fahrenheit.

While the trend in temperature increase is 0.0001604 Fahrenheit/day or 5.85 Fahrenheit/Century

The other coefficients are: c3 = -20, c4 = -7.833.

For a 2-year period the data plot is shown below along with the fitted model.

To model fluctuation as well in the data, we have used the modified model and then used the curve fitting tool to estimate new coefficients.

c1 = 52.74 Fahrenheit

c2 = 0.0001066 Fahrenheit/day = 3.89 Fahrenheit/century

c3 = -20.35

c4 = -7.835

c5 = -0.3887 (Very small value suggests minute contribution of high frequency sinusoidal waves)

c6 = -0.01226 (Very small value suggests minute contribution of high frequency sinusoidal waves)

It is also visible in the figure shown below that by adding these additional terms in the model is not improving the model fitting much.

By increasing the frequency of sine and cosine in the model associated with coefficients c5 and c6, the fluctuation can be modeled much better.

%% Computing the determinant

U = round(100*rand(10));

U = triu(U,1)+0.1*eye(10);

det(U)

det(U’)

det(U*U’)

cond(U,1);

%% Ill-conditioned matrix

n = 1:48;

kA = zeros(size(n));

for i = 1:length(n)

A = eye(n(i))-triu(ones(n(i)),1);

kA(i) = cond(A,1);

end;

figure; semilogy(n,kA);

hold on; semilogy(n,ones(size(n))*1/eps,’k:’);

% Pivot elements of A are 1

n = 53;

A = eye(n)-triu(ones(n),1);

detA = det(A);

b = zeros(length(A),1);

b(end) = 1;

x = A \ b;

normx = norm(x);

normb = norm(b);

%% Least squares

clear all

load McGuireAFB.dat

day = datenum(VarName1,’yyyymmdd’);

t = day-day(1);

temp = VarName2;

figure; plot(t, temp);

xlabel(‘Days (Starting from 1^{st} Jan. 1995)’);

ylabel(‘Temperature (F)’);

title(‘Historical temperature data’);

xlim([0 t(end)-1]);

grid on;

figure; plot(t(1:730), temp(1:730));

xlabel(‘Days (Starting from 1^{st} Jan. 1995)’);

ylabel(‘Temperature (F)’);

title(‘Historical temperature data (2-year data)’);

xlim([0 729]);

grid on;