B11

Contents

Called Functions

A41

clear all
n = 10;
t = linspace(0,10,n);
T = linspace(0,10,100);
y = randn(n,1);

base = {@(x) x.^(0), @(x) x.^1};
f = MyLS(base,t,y);
plot(T,f(T),'r',t,y,'o')

A42

Aufg42
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.754724e-35. 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  1.870835e-42. 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  4.301166e-49. 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  5.668695e-55. 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  5.449279e-62. 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  6.152716e-68. 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  3.078974e-76. 
Neue Basis: (t-2000)^i

A43

load Flugplan.mat
A0 = A^0;
A1 = A^1;
A2 = A^2;

disp('Genau zwei Flüge')
A2   = A2
disp('Max. zwei Flüge')
A012 = A0+A1+A2

disp(['Von Flugh. 4 nach Flugh. 10 benötigt man ' num2str(flug_anz(A,4,10)) ' Flüge.'])
Genau zwei Flüge

A2 =

     0     0     0     0     0     1     0     0     0     0
     0     0     0     1     0     0     0     1     0     0
     1     0     0     0     0     1     0     0     0     0
     1     1     0     0     1     0     0     0     1     0
     0     1     0     0     0     0     0     0     0     0
     0     1     1     0     1     0     0     0     1     1
     0     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     1     1     1     0     0
     0     0     0     0     0     0     0     0     0     0
     0     1     0     0     0     0     0     0     1     1

Max. zwei Flüge

A012 =

     1     1     0     0     0     1     0     0     0     0
     0     1     0     1     0     1     0     1     0     0
     1     1     1     0     1     1     0     0     1     0
     1     1     1     1     2     0     0     0     1     0
     1     1     0     0     1     0     0     0     0     0
     0     1     1     1     1     1     0     1     1     1
     0     0     0     0     0     0     1     0     0     0
     0     1     0     0     0     1     1     2     1     1
     0     0     0     0     0     0     0     0     1     0
     0     1     0     0     0     0     1     1     1     2

Von Flugh. 4 nach Flugh. 10 benötigt man 5 Flüge.

A44

WahrFalsch
a) ist wahr=1/falsch=0   :  0
b) ist wahr=1/falsch=0   :  1
c) ist wahr=1/falsch=0   :  0
d) ist wahr=1/falsch=0   :  1
e) ist wahr=1/falsch=0   :  0

a =

   1.1102e-16

f) ist wahr=1/falsch=0   :  1
g) ist wahr=1/falsch=0   :  0
h) ist wahr=1/falsch=0   :  0
Aufg42
%function Aufg42
clear all
n = 10;
t = linspace(0,10,n);
T = linspace(0,10,100);
y = randn(n,1);
for i = 1:n
    base{i} = @(x) x.^(i-1);
    f = MyLS(base,t,y);
    plot(T,f(T),'r',t,y,'o')
    title([num2str(i) ' Basisfunktionen'])
    %%%%%%%%%%%%%% Nicht Teil der Aufgabe %%%%%%%%%%%%%%%%%
    if mod(i,3)==1; snapnow; end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    pause(0.5)
end
pause(1)
clear base
t = linspace(2000,2010,n);
T = linspace(2000,2010,100);

for i = 1:n
    base{i} = @(x) x.^(i-1);
    f = MyLS(base,t,y);
    plot(T,f(T),'r',t,y,'o')
    title([num2str(i) ' Basisfunktionen'])
    %%%%%%%%%%%%%% Nicht Teil der Aufgabe %%%%%%%%%%%%%%%%%
    if mod(i,3)==1; snapnow; end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    pause(0.5)
end
pause(1)
clear base
disp('Neue Basis: (t-2000)^i')
for i = 1:n
    base{i} = @(x) (x-2000).^(i-1);
    f = MyLS(base,t,y);
    plot(T,f(T),'r',t,y,'o')
    title([num2str(i) ' Basisfunktionen'])
    %%%%%%%%%%%%%% Nicht Teil der Aufgabe %%%%%%%%%%%%%%%%%
    if mod(i,3)==1; snapnow; end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    pause(0.5)
end
%end
MyLS
function f = MyLS(base,t,y)
% f =  MyLS(base,t,y)
% Liefert eine Ausgleichskurve f(x) = b_1*base_1(x)+...+b_n*base_n(x)
% zu den Daten (t_i,y_i).
% INPUT: base  : Ein cell array mit m Basisfunktionen.
%        t     : n Knotenpunkte.
%        y     : n Werte (an den Knotenpunkten).

    n = length(t);
    m = length(base);
    A = zeros(n,m);

    for i =1:n
        for j =1:m
           A(i,j) = base{j}(t(i));
        end
    end

    y=A'*y;
    A=A'*A;

    coeff = A\y;

    f=@Myf;

    function sol = Myf(x)
       sol = 0;
       for k=1:m
           sol = sol+coeff(k)*base{k}(x);
       end
    end
end
Wahr - Falsch

Wahr - Falsch

Contents

a)

A=rand(10) + rand(10)';
disp(['a) ist wahr=1/falsch=0   :  ', num2str(0==norm(A-A'))])

b)

disp(['b) ist wahr=1/falsch=0   :  ', num2str(1)])

c)

disp(['c) ist wahr=1/falsch=0   :  ', num2str(0)])

d)

disp(['d) ist wahr=1/falsch=0   :  ', num2str(1)])

e)

disp(['e) ist wahr=1/falsch=0   :  ', num2str(0)])

f)

a=eps/2
disp(['f) ist wahr=1/falsch=0   :  ', num2str(1==1+a)])

g)

v = 2:10:20; w = linspace(1,10,20);
disp(['g) ist wahr=1/falsch=0   :  ', num2str(length(v)==length(w))])

h)

A=randn(10);
a=isempty(find(angle(A)));
b=~(norm(imag(A),inf)>0);
disp(['h) ist wahr=1/falsch=0   :  ', num2str(a==b)])
a2
%A2

A=rand(8);

%Max aus Spalte
max(A)

%Min aus Zeile
min(A')

%Max aller Einträge
max(max(A))

%Indizes der Elemente  > 0.5
[zeile,spalte]= find(A>0.75);

[zeile, spalte]
flug_anz
function n = flug_anz(A,k,j)
A1 = A;
n = 1;
while A1(4,10) == 0
    A1 = A1*A;
    n = n+1;
end
end