$30 off During Our Annual Pro Sale. View Details »

Simplify Challenging Software Problems with Rocket Science

listrophy
September 24, 2015

Simplify Challenging Software Problems with Rocket Science

Aerospace engineering is really no more magical than programming, and yet it's shrouded in such mystery and mysticism that practically no one bothers to study it. I'll show you how to apply concepts from rocket science to challenging software problems, allowing you to spend more time coming up with answers rather than interpreting inputs. We'll also learn to control the universe outside our glowing rectangles.

listrophy

September 24, 2015
Tweet

More Decks by listrophy

Other Decks in Programming

Transcript

  1. Simplify Challenging
    Software Problems with
    Rocket Science
    @bendyworks
    Brad Grzesiak — @listrophy

    View Slide

  2. –Ashe Dryden
    “Whenever Brad is drinking, you
    wanna make sure you're sitting
    next to him, because instead of
    being obnoxious, he teaches you
    orbital mechanics.”

    View Slide

  3. Heads up:
    1 Animated GIF

    View Slide

  4. Agenda
    • Reduce Cognitive Load
    • Visualize Simulations with Graphics
    • Control and Respond to Real World Processes

    View Slide

  5. Agenda
    • Reduce Cognitive Load
    • Visualize Simulations with Graphics
    • Control and Respond to Real World Processes

    View Slide

  6. we
    are
    not
    superheros

    View Slide

  7. Scalars & Collections
    Primitives & Arrays
    • x, y, z = 2, 3, 5
    • Math.sqrt(x**2 + y**2 + z**2)
    • array.zip(other).map{|(i,j)| i+j}
    • [m[0][0]*v[0]+m[0][1]*v[1],
    m[1][0]*v[0]+m[1][1]*v[1]]
    Vectors & Matrices
    • vector = Vector[2, 3, 5]
    • vector.magnitude # or vector.r
    • vector_1 + vector_2
    • matrix * vector


    View Slide

  8. “matrix”
    “times”
    “vector?”

    View Slide

  9. Linear Transformations
    • Scale, Rotate, Skew, Translate (with a trick)
    • Common in CSS3
    • Common in Kinetics & Kinematics

    View Slide

  10. Matrix Times Vector
    1.  ⽷a    b⽹⽷x⽹  
         ⽸c    d⽺⽸y⽺  
    2.  [x    y]  
         ⽷a    b⽹  
         ⽸c    d⽺  
    3.  ⽷ax+by⽹  
         ⽸cx+dy⽺  

    View Slide

  11. Matrix Times Vector
    def matrix_times_vector(m, v)
    a, b = m[0]
    c, d = m[1]
    x, y = v
    [
    a*x + b*y,
    c*x + d*y
    ]
    end
    require 'matrix'
    def matrix_times_vector(m, v)
    m * v
    end
    NOW
    WITH DIM
    CHECKS!

    View Slide

  12. Rotation Matrix
    R(θ)  =  ⽷cosθ  -­‐sinθ⽹  
                 ⽸sinθ    cosθ⽺  
    R(30deg)*⟨1,0⟩  =  ⟨0.87,0.5⟩  
    R(90deg)*⟨1,0⟩  =  ⟨0,1⟩

    View Slide

  13. Rotation Matrix
    R(-­‐30deg)*                        =  

    View Slide

  14. Agenda
    • Reduce Cognitive Load
    • Visualize Simulations with Graphics
    • Control and Respond to Real World Processes

    View Slide

  15. Why Graphic Simulations?
    • Complex Systems
    • High Sensitivity
    • Pattern Recognition Required
    • Seeking “Good Enough”

    View Slide

  16. In Aerospace Engineering
    • Launch Vibration Testing
    • “Kick” tests
    • Thermal Equilibrium
    • Designing to Safety Factor

    View Slide

  17. In Aerospace Engineering
    • Launch Vibration Testing
    • “Kick” tests
    • Thermal Equilibrium
    • Designing to Safety Factor
    • N-Body Orbital Trajectories

    View Slide

  18. The n-Body Problem
    • Newton’s Laws + Gravity
    • Solved for N=2
    • For N>2, “no general analytical solution,” except for
    special cases (e.g., Lagrangian Points)

    View Slide

  19. The n-Body Problem
    Gravity Force = x
    Newton’s 2nd Law Force = mass ⨉ acceleration
    Newton’s 3rd Law Force₁ = -Force₂
    Velocity-Acceleration
    Position-Velocity

    View Slide

  20. Wait a minute.
    Derivatives?

    View Slide

  21. Formal Derivative

    View Slide

  22. Our Approximation

    View Slide

  23. Our Approximation

    View Slide

  24. Our Approximation

    View Slide

  25. The n-Body Problem
    Gravity Force = x
    Newton’s 2nd Law Force = mass ⨉ acceleration
    Newton’s 3rd Law Force₁ = -Force₂
    Velocity-Acceleration
    Position-Velocity

    View Slide

  26. The n-Body Problem
    Gravity Force = x
    Newton’s 2nd Law Force = mass ⨉ acceleration
    Newton’s 3rd Law Force₁ = -Force₂
    Velocity-Acceleration vnow = vprev + anow dt
    Position-Velocity xnow = xprev + vnow dt

    View Slide

  27. The n-Body Problem
    Gravity Force = x
    Newton’s 2nd Law acceleration = Force ÷ mass
    Newton’s 3rd Law Force₁ = -Force₂
    Velocity-Acceleration vnow = vprev + anow dt
    Position-Velocity xnow = xprev + vnow dt

    View Slide

  28. Gravity Fnow = x
    Newton’s 2nd Law anow = Fnow ÷ m
    Newton’s 3rd Law (loop over each mass-pair)
    Velocity-Acceleration vnow = vprev + anow dt
    Position-Velocity xnow = xprev + vnow dt
    The n-Body Problem

    View Slide

  29. The n-Body Problem
    bodies.map do |body|
    [body, gravity(body, bodies-[body])]
    end.each do |(body, force)|
    accel = force / body.mass
    body.velocity += accel * dt
    body.position += body.velocity * dt
    end

    View Slide

  30. The n-Body Problem
    def gravity(body, others)
    others.reduce(Vector[0,0]) do |memo, other|
    offset = other.position - body.position
    memo + offset * G * body.mass * other.mass / offset.r**3
    end
    end

    View Slide

  31. (demo)

    View Slide

  32. Agenda
    • Reduce Cognitive Load
    • Visualize Simulations with Graphics
    • Control and Respond to Real World Processes

    View Slide

  33. The World is Complicated
    • “Assume no air resistance”
    • “Assume a frictionless surface”
    • “Assume perfect DC voltage”
    • “Assume no impact from general or special
    relativity”

    View Slide

  34. You simply cannot predefine a
    specific solution to a problem that
    is perturbed by the real world

    View Slide

  35. –Helmuth von Moltke the Elder
    “No battle plan ever survives
    contact with the enemy.”

    View Slide

  36. The Answer: React

    View Slide

  37. Feedback Controller

    View Slide

  38. Feedback Controller

    View Slide

  39. Feedback Controller

    View Slide

  40. PID Controller

    View Slide

  41. Controller
    P
    I
    D
    roportional
    ntegral
    erivative

    View Slide

  42. Feedback Controller
    diff == error

    View Slide

  43. Proportional
    P  =  error  =  desired  -­‐  actual

    View Slide

  44. Derivative
    D  =  (error  -­‐  prev_error)/dt

    View Slide

  45. Integral
    I  =  I  +  error*dt

    View Slide

  46. Our PID Controller
    loop do
    sleep 0.2
    curr_time = Time.now
    dt = curr_time - prev_time
    p = error = desired - actual
    i = i + error * dt
    d = (error - prev_error)/dt
    setThrust(0.1*p + 0.003*i + 0.08*d)
    prev_error, prev_time = error, curr_time
    end

    View Slide

  47. (demo)

    View Slide

  48. Agenda
    • Reduce Cognitive Load
    • Visualize Simulations with Graphics
    • Control and Respond to Real World Processes

    View Slide

  49. Photo Credits
    • “ABS/EUTELSAT-1 Launch” (Public Domain):

    http://www.spacex.com/media-gallery/detail/127081/4896
    • “Beer Actor” (CC-BY):

    https://www.flickr.com/photos/cogdog/21127813750/
    • “Up, up and away!” (CC-BY-SA):

    https://www.flickr.com/photos/kindercapes/5694816038
    • “I’m confused” (CC-BY-SA):

    https://www.flickr.com/photos/doctabu/342220423
    • “Cookie Monster Waiting” (no idea):

    https://www.google.com/search?q=cookie+monster+waiting
    • “Elmer Pump Heat Equation” (CC-BY-SA):

    https://commons.wikimedia.org/wiki/File:Elmer-pump-heatequation.png
    • “Owl Stuck” (CC-BY):

    https://www.flickr.com/photos/eben-frostey/7147015007


    View Slide

  50. Thank You!
    Brad Grzesiak
    [email protected]
    @listrophy

    View Slide