% Numerik D-MAVT, RW (Nipp), SS06
%
% This is the M-file solution to the first exercise sheet.
% To run, save this file to your account and ensure that the "Current directory"
% in MATLAB is the same as that where the file is saved.
%
% Then to run the file type "s1" in the command window
%
% Serie 1, A1
format compact;
e=1; while (1+e) > 1 e = e/2; end
disp(['my test: e=',num2str(2*e,15),'  MATLAB built in: e=',num2str(eps,15)]);
% output:
% my test: e=2.22044604925031e-16  MATLAB built in: e=2.22044604925031e-16

% Numerik D-MAVT, RW (Nipp), SS06
% Serie 1, A2
ltr=100; c=-1;	% left to right
for i=2:1e4 ltr=ltr+c*1/i; c=-c; end;
rtl=-1e-4; c=1;  % right to left
for i=1e4-1:-1:2 rtl=rtl+c*1/i; c=-c; end; rtl=rtl+100;
format long; format compact;
ltr,rtl,exact=99.69309718305994529172,
% output:
% ltr =
%   99.69309718306019
% rtl =
%   99.69309718305995
% exact =
%   99.69309718305995

% Numerik D-MAVT, RW (Nipp), SS06
% Serie 1, A3
format long; format compact;
% x is always the simple version, y the (better) sophisticated one
% a) use: a^3-b^3 = (a-b)*(a^2+a*b+b^2)
a=29790^(1/3); b=31;
x=a-b, y=(29790-b^3)/(a*a+a*b+b*b),
% output:
% x =
%     -3.468647899005362e-04
% y =
%      -3.468647898960239e-04
% b) use: log(a)-log(b) = log(a/b)
a=10001; b=10000;
x=log(a)-log(b), y=log(a/b),
% output:
% x =
%      9.999500033330833e-05
% y =
%      9.999500033329732e-05
% c) use: cos(a)-cos(b) = -2*sin(.5*(a+b))*sin(.5*(a-b)), cos(0)=1
a=.00001; b=0;
x=cos(a)-cos(b), y=-2*sin(.5*(a+b))*sin(.5*(a-b)),
% output:
% x =
%    -5.000000413701855e-11
% y =
%    -4.999999999958334e-11

% Numerik D-MAVT, RW (Nipp), SS06
% Serie 1, A4b
format long; format compact;
A=hilb(10); ev=eig(A); kappa=max(ev)/min(ev), cond(A),
% output:
% kappa =
%      1.602992684006399e+13
% ans =
%      1.602442026020877e+13

