%% Week 2
% Matlab codes for week 2

%% Problem 1

format long

A=rand(6);
matrixnorm=norm(A)
spectral_radius=max(abs(eig(A)))

%% Problem 2

A=[0.5, 0.5; -0.5, 0.25]

%% Problem 4

clear x, clear y
x(1)=1; for i=1:40 x(i+1)=2-2*(2-x(i))/(4-x(i)^2); end;
disp('iteration steps of the sequence x_i')
disp(x')
log_x_error=log(abs(x-sqrt(2)));

y(1)=1; y(2)=2; for i=2:15 y(i+1)=y(i)-(y(i)^2-2)/(y(i)+y(i-1)); end;
disp('iteration steps of the sequence y_i')
disp(y')
log_y_error=log(abs(y-sqrt(2)));

plot(log_x_error(1:end-1),log_x_error(2:end),log_y_error(1:end-1),log_y_error(2:end))
axis equal

legend('x','y')

%% Problem 5

d=3.4e-16;
a=1+d;
b=sqrt(a);
x=b-1

%% Problem 8

x=-25;
e=0;
for i=0:200
    e=e+x^i/factorial(i);
end
e

%% Problem 9

x=10^8;
v=1/(sqrt(x^2+1)-x)

%% Problem 10

x=10^-15;
v=((1+x)-1)/x
