Solution for Ex 1. Write the function 1
function [L, U] = LUnoPiv(A)2
% LU factorization without pivoting3
n = size(A,1); % size of A4
L = eye(n); % initialize5
for k = 1:n−
16
for i = k+1:n7
% multipliers for gaussian elimination8
L(i,k) = A(i,k)/A(k,k);9
for j = k:n10
% construct A11
A(i,j) = A(i,j)−
L(i,k)*A(k,j);12
end13
end14
end15
U = A;and then the following script 1
clear all2
close all3
% clc4
epsilon = 10^(−
15);5
% Define A6
A = [13 13 0; 2 2−
epsilon 4; 1 3 17];7
% define b8
xVera = [2;5;7]; b = A*xVera;9
% compute the solution10
[L, U] = LUnoPiv(A);11
y = L\b; xLUnoPiv = U\y;12
% compute the solution with pivoting13
[L, U, P] = lu(A);14
y = L\(P*b); xLUpermut = U\y;15
% compute the errors16
format short e17
ELUgauss = norm(xVera−
xLUnoPiv)/norm(xVera)18
ELUpermut = norm(xVera−
xLUpermut)/norm(xVera)1
Solution for Ex 2. At rst write the function 1
function [x,iter,err]=Jacobi(A,b,x0,tol,kmax)2
% Jacobi's iterative method for the solution of Ax=b3
% with tolerance 'tol' and maximum number of iteration4
% 'kmax'5
D=diag(diag(A)); DI=diag(1./diag(A));6
J=−
DI*(A−
D);7
disp(['Spectral radius of the iteration matrix = ',...8
num2str(max(abs(eig(J))))]);9
b1=DI*b; x1=J*x0+b1; k=1;10
while(norm(x1−
x0)>tol*norm(x1) && k<=kmax)11
x0=x1;12
x1=J*x0+b1;13
err(k)=norm(x1−
x0,inf);14
k=k+1;15
end16
x=x1; iter=k−
1;Then, the following script 1
% clear all2
% close all3
% define the problem4
v = [4 1 zeros(1,4)];5
A = toeplitz(v);6
b = A*2*ones(6,1);7
% use Jacobi8
[x,iter1,err1]=Jacobi(A,b,zeros(6,1),1.e−
10,200);2