Contents
A9
clear all;
A=rand(8);
My1 = (max(sum(A)));
fprintf('MyNorm1 = %16.16f, MAATLAB Norm = %16.16f, Differenz = %16.16f\n',...
My1, norm(A,1),My1-norm(A,1));
MyInf = (max(sum(A')));
fprintf('MyNormInf = %16.16f, MAATLAB Norm = %16.16f, Differenz = %16.16f\n',...
MyInf, norm(A,'inf'),MyInf-norm(A,'inf'));
AA=A'*A;
My2 = sqrt(max(eig(AA)));
fprintf('MyNorm2 = %16.16f, MAATLAB Norm = %16.16f, Differenz = %16.16f\n',...
My2, norm(A,2),My2-norm(A,2));
MyNorm1 = 5.5637714951249038, MAATLAB Norm = 5.5637714951249038, Differenz = 0.0000000000000000
MyNormInf = 5.7578604296358735, MAATLAB Norm = 5.7578604296358735, Differenz = 0.0000000000000000
MyNorm2 = 4.5978785008480658, MAATLAB Norm = 4.5978785008480632, Differenz = 0.0000000000000027
A10
fprintf('\n')
clear all;
n=100;
x = rand(n,1);
fprintf('Summe\n')
s = 0;
for i = 1:n,
s = s + x(i);
end
fprintf('Result from the ''for'' loop : %24.16f\n',s);
fprintf('Result from ''sum'' function : %24.16f\n',sum(x));
fprintf('\nMin\n')
xmin = x(1);
for i = 2:n,
xmin = min(xmin,x(i));
end
fprintf('Result using the ''for'' loop : %24.16f\n',xmin);
fprintf('Result from ''min'' function : %24.16f\n',min(x));
fprintf('\nMittelwert\n')
s = 0;
for i = 1:n,
s = s + x(i);
end
s_mean_for = s/n;
fprintf('Result from the ''for'' loop : %24.16f\n',s_mean_for);
fprintf('Result from ''mean'' function : %24.16f\n',mean(x));
fprintf('\nstd\n')
s = 0;
mu = mean(x);
for i = 1:n,
s = s + (x(i)-mu)^2;
end
std_for = sqrt(s/(n-1));
fprintf('Result from the ''for'' loop : %24.16f\n',std_for);
fprintf('Result from ''std'' function : %24.16f\n',std(x));
Summe
Result from the 'for' loop : 47.1349005220715327
Result from 'sum' function : 47.1349005220715327
Min
Result using the 'for' loop : 0.0046342241340674
Result from 'min' function : 0.0046342241340674
Mittelwert
Result from the 'for' loop : 0.4713490052207153
Result from 'mean' function : 0.4713490052207153
std
Result from the 'for' loop : 0.2917067154093339
Result from 'std' function : 0.2917067154093339
A11
A = [1 -1 3; 3 5 -1; 0 5 -3];
b = [5; 1; -22];
x = A\b
n = 6; z = zeros(n-2,1);
cr = [-2; 1; z];
D = toeplitz(cr);
b = ones(n,1);
x = D\b
x =
10.3846
-6.8462
-4.0769
x =
-3.0000
-5.0000
-6.0000
-6.0000
-5.0000
-3.0000
A12
d = [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1, 1, 2, 2,...
2, 2, 1, 84, 2, 1, 1, 15, 3, 13, 1, 4, 2, 6, 6, 99, 1, 2,...
2, 6, 3, 5, 1, 1, 6, 8, 1, 7, 1, 2, 3, 7, 1, 2, 1, 1];
MyPI=1./d(end);
for i = d(end-1:-1:2)
MyPI=1./(i+MyPI);
end
MyPI=d(1)+MyPI;
fprintf('MyPI = %12.12e, MAATLAB PI = %12.12e, Differenz = %12.12e\n',...
MyPI,pi,MyPI-pi);
MyPI = 3.141592653590e+00, MAATLAB PI = 3.141592653590e+00, Differenz = 0.000000000000e+00