Kapitel 14
geometry-Package
>
restart:
with(geometry):
> point(A,1,1), point(B,3,5), point(C,6,3);
> line(g, [A,B]);
> _EnvHorizontalName:='x':_EnvVerticalName:='y':
> detail(g);
> line(h, [C, point(``,0,0)]);
> intersection(IP,g,h);
> coordinates(IP);
> circle(c, [A,B,C]):
> intersection(IP,h,c);
> map(coordinates, IP);
> point(P, [7,py]):
> AreCollinear(A,B,P);
AreCollinear: "hint: could not determine if -26+2*py is zero"
> draw([A,B,C,g,h,c], color=black, scaling=constrained);
Das Package geom3d
> restart:with(geom3d):
Warning, the name polar has been redefined
Über die Umgebungsvariablen _EnvXName, _EnvYName, _EnvZName kann man die Namen der Achsen festlegen:
> _EnvXName:='x1':_EnvYName:='x2':_EnvZName:='x3':_EnvTName:='t':
> point(A,4,-1,1):point(B,7,1,0):point(C,4,7,-3):
> plane(e1,[A,B,C]):line(l1,[A,B]):sphere(k,[point(M,4,0,3),3]):
> detail(l1);
> detail(e1);
> NormalVector(e1);
> detail(k);
> intersection(p,l1,k);
geom3d/areinterls: "two points of intersection"
> detail(p[1]);
> coordinates(p[2]);
>
LinearAlgebra
> restart:
> with(LinearAlgebra);
Vektoren
> v1z:= <a|b|c>; v1s:=<a,b,c>;
> v2:= Vector[row](3, n->x^n);Transpose(v2);
> v1z + v2 ;v1s+v2;
Error, (in rtable/Sum) invalid arguments
> v1z * 2;
> map(x->x+3,v1z);
> DotProduct(v1z, v2,conjugate=false);
> v1z . Transpose(v2);
> v2 . v1s;
> Transpose(v2).v1z;
> DotProduct(v1z, v2);
> DotProduct(v1s, v2);
>
DotProduct(<1, I>, <1,I> );
> DotProduct( <1, I>, <1,I>, conjugate=false );
> CrossProduct(v1s,v2);
> CrossProduct(<1|3|4>,<a|b|c>);
>
> Norm( <a,b,c> );
> Norm( <a,b,c>, 1);
> Norm( <a,b,c>, 2);
> Normalize( <1|2|3>,2 );
> VectorAngle( <1,0,0>,<1,1,1> );
> evalf(%*180/Pi);
Matrizen
> restart:with(LinearAlgebra):
> Matrix(2,2,[[a,b],[c,d]]);<<a|b>,<c|d>>;<<a,c>|<b,d>>;
> Matrix( [[a,b,c], [d,e,f], [g,h,i]]);
> Matrix( 3,3, (n,m)->n*x^m);
> Matrix( 3,5,storage=sparse);
> IdentityMatrix(3,4);
>
> DiagonalMatrix([1,<<1,-1>|<-1,1>>,2,3]);
> BandMatrix( [1,x,-1], 1,4);
> ToeplitzMatrix( <a,b,c,d>,4,symmetric);
> RandomMatrix(15,15);
> RandomMatrix(2,2,generator=rand(0..10)/10);
Zugriff auf Matrizenelemente
> restart:with(LinearAlgebra):
> m1:=<<1|2|3|4>,<a|b|c|d>,<e|f|g|h>,<w|x|y|z>>;
> m1[2..3,2..4];
> SubMatrix(m1,1..2,3..4);
> SubMatrix(m1,[3,1],[2..4,1]);
> Row(m1, 2);
> Column(m1,2);
> v1:=Matrix(1,4,(m,n)->x^n);
> m1[1,3]:=5;
> m1[3..3,1..4]:=v1;m1;
> m2:=Matrix(4,4):
> m2[2..4,2..4]:=m1[1..3,1..3];
> m2;
> m2[1,1]:=5;m2;
Elementare Matrizenoperationen
> restart:with(LinearAlgebra):
> m1:=<<a,c,e>|<b,d,f>>;
> m2:=<<r|s|t>,<u|v|w>>;
> Transpose(m2);
> m2 * 3;
> m2 + 3;
> map(sqrt, m2);
> m1 + Transpose(m2);
> m1 . m2;
> m2 . m1;
> m3:=Matrix([[1,2],[3,4]]);
> 1/m3;
> m3^3, m3 . m3 . m3;
Produkte
> restart:with(LinearAlgebra):
> m1:=<<a|b|c>,<d|e|f>,<g|h|i>>:
> v1:=<u|v|w>;
> v2:=<u,v,w>;
> m1 . v2;
> v1 . m1 ;
> v1 . v2;
> v2 . v1;
Determinanten, Inverse, ...
> restart:with(LinearAlgebra):
> m1:=<<1| 2| 3>,<4|-5| 6>,<9| 8| 7>>;
> Determinant(m1);
> m2:=MatrixInverse(m1);
> Rank(m1);
> v:=<14,12,46>;
> m2 . v;
> m1 . %;
> Trace(m1);
> Norm(<<a|b|c>,<d|e|f>,<g|h|i>>);
> Norm(<<a|b|c>,<d|e|f>,<g|h|i>>,Frobenius);
> Norm(<<a|b|c>,<d|e|f>,<g|h|i>>,1);
> Norm(<<1|2>,<3|7>>,2);
> allvalues(%);
> Rank( <<1|2>,<3|4>> );
> Rank( <<1|2>,<3|6>> );
Lineare Gleichungssysteme
> restart:with(LinearAlgebra):
> A:=<<1|2|3>,<4|-5|6>,<9|8|7>>:
> b:=<14,12,46>:
> LinearSolve(A,b);
> A:=<<1|2|3>,<4|8|12>,<1|-1|0>>:
>
LinearSolve(A,b);
Error, (in LinearAlgebra:-LA_Main:-LinearSolve) inconsistent system
> NullSpace(A);
> A . %[1];
> A:=<<1|2|3>,<4|5|6>,<0|0|0>>:
> b:=<1,2,0>:
> lsg:=LinearSolve( A,b,free='t');
> A . lsg ;
> A := <<3,0,4.0>|<-2,3,4>>:
> b := <1,2,4>:
> LinearSolve(A,b);
Error, (in LinearAlgebra:-LA_Main:-LinearSolve) inconsistent system
> X:=LeastSquares(A,b);
> A . X;
> Norm(A.X-b,2);
> glsys:=[2*y+x+3*z-16=-2,4*x-5*y+6*z=12,9*x+8*y+7*z=46]:
> glmat1:=GenerateMatrix(glsys, [x,y,z]);
> glmat2:=GenerateMatrix(glsys, [x,y,z], augmented=true);
> LinearSolve(glmat2);
> glmat1[1] . %;
>
>
Umformungen
> restart:with(LinearAlgebra):
> m:=RandomMatrix(4,5);
> (P,L,U):=LUDecomposition(m);
> P.L.U;
> U1,R:=LUDecomposition(m,output=['U1','R']);
> U1.R;
> mat:=RandomMatrix(4,4);Pivot(mat,2,3);
Eigenwerte, Eigenvektoren
> restart:with(LinearAlgebra):
> m1:=<<41, 5, -10>|<3, 39, -6>|<-14,-14, 64>>;
> ew:=Eigenvalues(m1);
> ev:=Eigenvectors(m1,output='list');
> Eigenvectors(m1);
> CharacteristicPolynomial(m1, lambda);
> m1 - DiagonalMatrix(<lambda,lambda,lambda>);Determinant(%);
> solve(%);
>
>
Orthonormalbasen
> restart:with(LinearAlgebra):
> v1:=<3|4|0>: v2:=<2|-1|3>: v3:=<-1|0|2>: v4:=<1|-2|1>:
> GramSchmidt([v1,v2,v3,v4]);
> onb:=GramSchmidt([v1,v2,v3,v4],normalized=true);
> DotProduct(onb[1], onb[2]), DotProduct(onb[2], onb[2]);
> with(tensor);
>