Contents

Called Functions

A1

clear all; close all;
bild = 'Kunst.jpg';

[comp, spar] = Aufgabe1(bild,50);
disp(['comp = ', num2str(comp) ,' spar = ', num2str(spar)])
[comp, spar] = Aufgabe1(bild,40);
disp(['comp = ', num2str(comp) ,' spar = ', num2str(spar)])
comp = 72.8733 spar = 491.8945
comp = 78.4722 spar = 529.6875

A2 a)

clear all; close all;
x=linspace(-3,3,7);
for k=2:4
   disp(['k = ' num2str(k)])
   disp(aufgabe2a(x,k))
end
k = 2
    26    17    10     5     2     1     2

k = 3
   135    72    33    12     3     0    -3

k = 4
   701   305   109    29     5     1     5

b)

clear all; close all; figure;
aufgabe2b

A3 a)

clear all; close all;
disp(aufgabe3a(5))
     0     1     2     3     4
     1     2     3     4     0
     2     3     4     0     1
     3     4     0     1     2
     4     0     1     2     3

b)

clear all; close all;
S = aufgabe3b(5);
disp(S)
disp(S{4})
    [0]    [2x2 double]    [3x3 double]    [4x4 double]    [5x5 double]

     0     1     2     3
     1     2     3     0
     2     3     0     1
     3     0     1     2

A4

clear all; close all;
aufgabe4
err
err =

    1.7218


err =

    1.7218

Aufgabe1
function [comp, spar] = Aufgabe1(bild,k)

% Einlesen der Bilddatei
A = imread(bild);
% Informationen über A
Ainfo=whos('A');

% Darstellung der Bilddatei
subplot(2,1,1);
image(A)

A = double(A);

% Wende svd auf jede Farbkomponente separat an
for i=1:3
    [U,S,V] = svd(A(:,:,i),0);

    % Komprimiert ablegen.
    Us(:,:,i) = (U(:,1:k));
    Ss(:,:,i) = (S(1:k,1:k));
    Vs(:,:,i) = (V(:,1:k));

    B(:,:,i) = Us(:,:,i)*Ss(:,:,i)*Vs(:,:,i)';
end

%Berechne Kompressionsrate
Us=uint8(Us);  Ss=uint8(Ss);  Vs=uint8(Vs);
Uinfo =whos('Us'); Sinfo =whos('Ss'); Vinfo=whos('Vs');

comp = (1-(Uinfo.bytes+Vinfo.bytes+Sinfo.bytes)/Ainfo.bytes)*100;
spar = (-(Uinfo.bytes+Vinfo.bytes+Sinfo.bytes)+Ainfo.bytes)/1024;
% Darstellung der Komprimierten Bilddatei
B=uint8(B);
subplot(2,1,2);
image(B)
aufgabe2a
function y = aufgabe2a(x,k)
if k<0
    error('Fehler: k < 0 nicht definiert');
end

if k==0
    y = ones(size(x));
elseif k==1
    y = 2-x;
else
    y = (2-x).*aufgabe2a(x,k-1) + aufgabe2a(x,k-2);
end
aufgabe2b
clear all

x = linspace(1,3,200);

y2 = aufgabe2a(x,2);
y4 = aufgabe2a(x,4);

plot(x,y2,'r',x,y4,'b--')
axis([1 3 1 3]);
legend('p_2(x)','p_4(x)','Location','NorthEastOutside');
aufgabe3a
function M = aufgabe3a(n)

M = zeros(n, n);
for x = 0:n-1
    for y = 0:n-1
        M(x+1,y+1) = mod(x+y, n);
    end
end
end
aufgabe3b
function M = aufgabe3b(N)

M = cell(1, N);
for k = 1:N
    M{k} = AddTab(k);
end
end
aufgabe4

Contents

clear all;

a)

load('aufgabe4daten')

A = [exp(-x2)' cos(pi*x1)' (x1+x2)'];

coef = A\y';

f=@(x1,x2) coef(1)*exp(-x2)+coef(2)*cos(pi*x1)+coef(3)*(x1+x2);

err = norm(y-f(x1,x2))

b)

plot3(x1,x2,y,'k*')

px1=linspace(-1,1,20);
px2=px1;

[X,Y] = meshgrid(px1,px2);
hold on
surf(px1,px2,f(X,Y))
alpha(0.5)