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. ⎕IO←0
  7. DELTA←1
  8. O←N←20
  9. M←L←1
  10. A←O N M L 4⍴0
  11. A[0;;;;2]←-(÷○2÷N)×2○○2×(⍳N)÷N
  12. A[1;;;;2]←-(÷○2÷N)×2○○2×((-DELTA)+⍳N)÷N
  13. T←1
  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+T←T+1)/LOOP
  19. DA←O N M L 4 4⍴0
  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 4⍉DA
  26. F←(0 1 2 3 5 4⍉DA)-DA
  27. T←0
  28. LOOP2:
  29. DRAW
  30. →(O>T←T+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