> #=================================

> # Testaufgabe 6

> #=================================

> restart; with(linalg):

Warning, new definition for norm

Warning, new definition for trace

> G:=y=a*t^2+b; # Modell Gleichung

[Maple Math]

> G[i]:=y[i]=a*t[i]^2+b; # i=1,2,3; 3 Gleichungen zwei Unbekannte

[Maple Math]

> A:=matrix(3,2, [(-1)^2,1, 0^2,1, 2^2,1]); f:=vector([1,2,-3]); T:=vector([-1,0,2]);

[Maple Math]

[Maple Math]

[Maple Math]

> # a) Ausnahmsweise Normalgleichungen

> ATA:=multiply(transpose(A), A); ATf:=multiply(transpose(A), f); evalm(multiply(inverse(ATA),ATf));ag:=augment(ATA,ATf); agg:=gausselim(ag);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> x:=backsub(agg); x:=evalm(map(evalf,x)); # x in Bruechen und Dezimalen

[Maple Math]

[Maple Math]

> # teste Residuum

> rv:=evalm(multiply(A,x)-f); r:=sqrt(dotprod(rv,rv)); r:=evalf(r);

[Maple Math]

[Maple Math]

[Maple Math]

> pl:=[[T[ii],f[ii]] $ii=1..3]; plot({pl,[t,x[1]*t^2+x[2], t=-1.2..2.2] }, t=-1.2..2.2, y=-4..3); #, style=point);

[Maple Math]

>

> # b) Jetzt mit Givens

> A:=augment(A,f); A[1,1]:=1.0*A[1,1]: # zwinge Maple mit Dezimalen zu rechnen

[Maple Math]

> n:=3; m:=3; read `givensOQ.src`; # Berechnung von Q nicht noetig

> n:=3; m:=3; read ` givensOQ.src`;

[Maple Math]

[Maple Math]

[Maple Math]

> x[2]:=R[2,3]/R[2,2];

[Maple Math]

> x[1]:=(R[1,3]-x[2]*R[1,2])/R[1,1];

[Maple Math]

> plot({pl,[t,x[1]*t^2+x[2], t=-1.2..2.2] }, t=-1.2..2.2, y=-4..3);

>