metric2calc.red 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. % calculation of metric tensor (2-dim space-time)
  2. off echo;
  3. on revpri;
  4. n:=2;
  5. operator x$
  6. x(0):=t; x(1):=lambda0;
  7. % metric
  8. array g(n,n)$
  9. % rules
  10. trig1:={sin(~x)^2=>(1-cos(x)^2)}$ let trig1$
  11. % procedures
  12. procedure scalprod(a,b);
  13. begin integer n;
  14. n:=first(length(a))-1;
  15. result:=for i:=0:n-1 sum a(i)*b(i);
  16. return result
  17. end;
  18. procedure showmatrix(mm);
  19. begin integer m,n;l:=length(mm);m:=first(l)-1;n:=second(l)-1;
  20. matrix hhm(m,n);
  21. for i:=0:m-1 do for j:=0:n-1 do hhm(i+1,j+1):=mm(i,j);
  22. write hhm end;
  23. procedure showvector(vv);
  24. begin integer n;n:=first(length(vv))-1;
  25. matrix hhv(n,1);
  26. for i:=0:n-1 do hhv(i+1,1):=vv(i);
  27. write hhv end;
  28. array f(n+1), dfdt(n+1), dfdl(n+1)$
  29. % current radius
  30. a:=a0*sqrt(1-t^2);
  31. % surface of hyper sphere in t and lambda
  32. f(0):=a*cos(lambda0);
  33. f(1):=a*sin(lambda0);
  34. f(2):=a0*t;
  35. for i:=0:n do dfdt(i):=df(f(i),x(0));
  36. for i:=0:n do dfdl(i):=df(f(i),x(1));
  37. g(0,0):=scalprod(dfdt,dfdt)$
  38. g(0,1):=scalprod(dfdt,dfdl)$
  39. g(1,0):=scalprod(dfdl,dfdt)$
  40. g(1,1):=scalprod(dfdl,dfdl)$
  41. write "f = "; showvector(f);
  42. write "df/dt = "; showvector(dfdt);
  43. write "df/dl = "; showvector(dfdl);
  44. write "g = "; showmatrix(g);
  45. off revpri;
  46. on echo;
  47. end;