# Polygon Project Methods and Details # For all parts of this help, a Polygon on n vertices is represented by a list of n+1 points [x,y] with the first and last entries the same. with(linalg): # Champs Champs:=proc(L) local cha,rec,i: if nops(L)=0 then RETURN(FAIL): fi: cha:={1}: rec:=evalf(abs(L[1][1])): for i from 2 to nops(L) do if evalf(abs(L[i][1]))>rec then cha:={i}: rec:= evalf(abs(L[i][1])): elif abs(L[i][1])=rec then cha:=cha union {i}: fi: od: cha: end: #EVC(M): the list of [eigenvalue,eigenvector] in weakly decreasing order of the absolute value of the eigenvalues EVC:=proc(M) local i,L,L1,cha,surv: L:=[evalf(eigenvectors(M))]: if {seq(L[i][2],i=1..nops(L))}<>{1.} then print(`Some eigenspaces are not one-dimensional`): RETURN(FAIL): fi: L:=[seq([L[i][1],Nor( convert(L[i][3][1],list) )],i=1..nops(L))]: L1:=[]: while L<>[] do cha:=Champs(L): L1:=[op(L1),seq(evalf(L[i]), i in cha)]: surv:={seq(i,i=1..nops(L))} minus cha: L:=[seq(L[i],i in surv)]: od: L1: end: #Nor Nor:=proc(v) local i,a: a:=evalf(sqrt(add(abs(v[i])^2,i=1..nops(v)))): if a<10^(-Digits+2) then RETURN(FAIL): fi: [seq(v[i]/a,i=1..nops(v))]: end: #CB(M,V): inputs a matrix M and a vector V and outputs the list of coefficients #expressing V in terms of the eigenvectors of M (arranged according to EVC) CB:=proc(M,V) local M1,i: M1:=EVC(M): M1:=[seq(M1[i][2],i=1..nops(M1))]: Coeffs(V,M1): end: # Coeffs(V,M): Coeffs:=proc(V,M) local var, equats, sols: var := {seq(a[i], i = 1 .. nops(V))}: equats:={seq(sum(a[i]*M[i][j], i = 1 .. nops(V)) = V[j], j = 1 .. nops(V))}: sols:=solve(equats,var): eval(convert(var, list),sols): end: