You are on page 1of 28

> restart;

> with(linalg):
> with(linearalgebra):
warning, the protected names norm and trace have been redefined and unprotected
warning, the name gramschmidt has been rebound
> restart;
> with(linalg):
> with(linearalgebra):
warning, the protected names norm and trace have been redefined and unprotected
warning, the name gramschmidt has been rebound
> matrandoixungtrucgiao:=proc(n,l::list)
> local i,a,f,g,p,s,k,e,v;
> if (nops(l)<1 or nops(l)>n) then
print('bannhapsogiatririengsai,vuilongnhaplai!');break;fi;f:=matrix(n
,n,0);s:=1;k:=0;for i to nops(l) do
s:=s*l[i];f[i,i]:=l[i];k:=k+abs(f[i,i]);od;if (nops(l)<>n) then
s:=0;fi;mtdx:=proc(n) local j;do g:=randommatrix(n,n,generator=-
2..2,outputoptions=[shape=symmetric]);if
type(convert(eigenvalues(g),list),'list(integer)') then
return(g);fi;od;end: a:=mtdx(n);(e,v):=eigenvectors(a);g:=v[1..-
1,1];for i from 1 to n do g:=g,v[1..-
1,i];od;p:=convert(gramschmidt([g],normalized),matrix);if ((abs(s)=1)
and (k=n)) then
print('motmatrandoixungtrucgiaothoamanyeucau,nhanenterdedoimatrankhac
!');return(multiply(matrixinverse(p),f,p));else if (abs(s)=0) then
print('khongcomatrandoixungtrucgiaonaothoaman,bancomuonnhanmatrandoix
ungsuybiensaukhong?');return(multiply(matrixinverse(p),f,p));else
print('khongcomatrandoixungtrucgiaonaothoaman,bancomuonnhanmatrandoix
ungkhongsuybiensaukhong?');return(multiply(matrixinverse(p),f,p));fi;
fi;
> end:
warning, `mtdx` is implicitly declared local to procedure `matrandoixungtrucgiao`
>
> m:=matrandoixungtrucgiao(4,[1,1,-1,1]);
MotMaTranDoiXungTrucGiaoThoaManYeuCau , NhanEnterDeDoiMaTranKhac !
1 0 0 0 
 
 2 6 2 6 3 
0 − −
 
 3 6 9 
 
M :=  6 2 2

3 
0 − 0 −
 6 3 
 
 
 
 6 3 2 3 1 
0 − − 
 9 3 3 
> f:=multiply(m,m);
1 0 0 0
 
0 1 0 0
F :=  
0 0 1 0

0 0 0 1

>

You might also like