maxwell.apl 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. See Chaitin 1986, Physics in APL2, p. 20
  2. Maxwell -- 4-vector potential vacuum field equations
  3. Transcribed by Daniel Llorens - 2013
  4. With GNU APL do apl -f maxwell.apl
  5. MAXWELL
  6. IO0
  7. DELTA1
  8. ON20
  9. ML1
  10. AO N M L 40
  11. A[0;;;;2]←-(÷○2÷N2○○2×(⍳NN
  12. A[1;;;;2]←-(÷○2÷N2○○2×((-DELTA)+⍳NN
  13. T1
  14. LOOP:
  15. X←(1⌽[0]A[T;;;;])+(1⌽[1]A[T;;;;])+(1⌽[2]A[T;;;;])
  16. Y←(¯1⌽[0]A[T;;;;])+(¯1⌽[1]A[T;;;;])+(¯1⌽[2]A[T;;;;])
  17. A[T+1;;;;]←X+Y-A[T-1;;;;]+4×A[T;;;;]
  18. →(O>1+TT+1)/LOOP
  19. DAO N M L 4 40
  20. DA[;;;;;0]←((1⌽[0]A)-(¯1⌽[0]A))÷2×DELTA
  21. DA[;;;;;1]←-((1⌽[1]A)-(¯1⌽[1]A))÷2×DELTA
  22. DA[;;;;;2]←-((1⌽[2]A)-(¯1⌽[2]A))÷2×DELTA
  23. DA[;;;;;3]←-((1⌽[3]A)-(¯1⌽[3]A))÷2×DELTA
  24. 'LORENTZ CONDITION: MAX|DIV| = 0?'
  25. ⌈/,|+/0 1 2 3 4 4DA
  26. F←(0 1 2 3 5 4DA)-DA
  27. T0
  28. LOOP2:
  29. DRAW
  30. →(O>TT+1)/LOOP2
  31. DRAW
  32. 'Ex' SHOW F[T;;0;0;1;0]
  33. 'Ey' SHOW F[T;;0;0;2;0]
  34. 'Ez' SHOW F[T;;0;0;3;0]
  35. 'Bx' SHOW F[T;;0;0;3;2]
  36. 'By' SHOW F[T;;0;0;1;3]
  37. 'Bz' SHOW F[T;;0;0;2;1]
  38. NAME SHOW F
  39. →(^/0=F)/0
  40. ' '
  41. NAME,' AT TIME = ',⍕T×DELTA
  42. FRAME(-⌊26+25×F)⌽((⍴F),52)⍴'⋆',51' '
  43. FRAME PIC
  44. '-',[0]('|',' ',' ',(⍕N 1⍴⍳N),' ',' ','|',PIC,'|'),[0]'-'
  45. MAXWELL