Robert M. Corless
Department of Applied Mathematics
University of Western Ontario
London, Canada

Copyright 2001 by Robert M. Corless
All rights reserved

Programming in Maple 

Программирование в Maple

Procedures 

Процедуры

Example: Modified Gram-Schmidt 

Пример: Преобразования Грэм-Шмидта

> restart;
> read "D:/books/ess/programs/mgs.mpl";
> with(LinearAlgebra):
> m, n := 30,27;

m, n := 30, 27

> A := RandomMatrix(m,n);

A := _rtable[4521592]

> Digits := trunc(evalhf(Digits));

Digits := 14

> #st := time(): Q,R := MGS1(A); time()-st; # BAD THING TO DO
> st := time(): Q,R := MGS1( evalf(A) ); time()-st;

Q, R := _rtable[4430752], _rtable[4410600]

1.929

> Norm( Q.R - A, infinity )/Norm(A,infinity);

.27550946273835e-13

> Norm( HermitianTranspose(Q).Q - IdentityMatrix(n), infinity );

.159951392408874682e-11

> st := time(): Q,R := MGS2( evalf(A) ): time()-st;

3.780

> Norm( Q.R - A, infinity)/Norm(A,infinity);

.95130874855135e-14

> Norm( HermitianTranspose(Q).Q - IdentityMatrix(n), infinity );

.837810723575138638e-12

> st := time(): Q,R := MGS3( evalf(A) ): time()-st;

1.828

> Norm( Q.R - A, infinity)/Norm(A,infinity);

.95130874855135e-14

> Norm( HermitianTranspose(Q).Q - IdentityMatrix(n), infinity );

.837810723575138638e-12

> st := time(): Q,R := MGS4( evalf(A) ): time()-st;

1.749

> Norm( Q.R - A, infinity)/Norm(A,infinity);

.95130874855135e-14

> Norm( HermitianTranspose(Q).Q - IdentityMatrix(n), infinity );

.837810723575138638e-12

> read "D:/books/ess/programs/mgs.mpl";
> st := time(): Q,R := MGS5( evalf(A) ): time()-st;

2.303

> Norm( Q.R - A, infinity)/Norm(A,infinity);

.21137775625707e-13

> Norm( HermitianTranspose(Q).Q - IdentityMatrix(n), infinity );

.824002324706363254e-12

С официального разрешения                    © 2002 Waterloo Maple, Inc

 
Hosted by uCoz