newton.apl 822 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ⍝ See Chaitin 1986, Physics in APL2, p. 14
  2. ⍝ Newton -- Orbits
  3. ⍝ Transcribed by Daniel Llorens - 2013
  4. ⍝ With GNU APL do apl -f newton.apl
  5. ∇NEWTON
  6. ⎕IO←0
  7. BODIES←2
  8. ORBIT←50 50⍴' '
  9. G←.6674E¯10
  10. T←0
  11. DELT←50
  12. M←6E24 10
  13. V←X←BODIES 3⍴0
  14. X[1;0]←1E7
  15. V[1;1]←6E3
  16. STEP←1
  17. LOOP:
  18. F←(⍳BODIES)∘.FORCE⍳BODIES
  19. A←⊃(+/F)÷M
  20. V←V+A×DELT
  21. X←X+V×DELT
  22. T←T+DELT
  23. DRAW
  24. →((12×15)≥STEP←STEP+1)/LOOP
  25. ∇F←I FORCE J
  26. F←3⍴0
  27. →(I=J)/0
  28. DELX←X[J;]-X[I;]
  29. R←(+/DELX⋆2)⋆.5
  30. F←(G×M[I]×M[J]÷R⋆2)×(DELX÷R)
  31. ∇DRAW
  32. ORBIT[25+⌊X[0;0]÷5E5;25+⌊X[0;1]÷5E5]←'E'
  33. ORBIT[25+⌊X[1;0]÷5E5;25+⌊X[1;1]÷5E5]←'⋆'
  34. →(0≠15|STEP)/0
  35. ' '
  36. 'TIME IN HOURS = ',⍕T÷60×60
  37. FRAME ORBIT
  38. ∇FRAME PIC
  39. '|',('-',[0]PIC,[0]'-'),'|'
  40. NEWTON