Advertisement
Guest User

Arm

a guest
Apr 6th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.32 KB | None | 0 0
  1. using PyPlot
  2. R=1
  3.  
  4. a1x(g) = R*cos(g[1])
  5. a2x(g) = R*cos(g[2])
  6. a1y(g) = R*sin(g[1])
  7. a2y(g) = R*sin(g[2])
  8.  
  9. a1xD(g) = -R*sin(g[1])
  10. a2xD(g) = -R*sin(g[2])
  11. a1yD(g) = R*cos(g[1])
  12. a2yD(g) = R*cos(g[2])
  13.  
  14.  
  15. ax(g) = a1x(g) + a2x(g)
  16. ay(g) = a1y(g) + a2y(g)
  17.  
  18. Fskj=[1.3;1.3]
  19. J(g) = [a1xD(g) a1yD(g); a2xD(g) a2yD(g)]
  20. Fv(g) = [ax(g); ay(g)] - Fskj
  21.  
  22. guess=[pi/3;pi/5]
  23. for i in 1:50
  24.     guess = guess - inv(J(guess))\Fv(guess)
  25. end
  26.  
  27. println(guess)
  28. println(Fv(guess) + Fskj)
  29.  
  30. plot([1.3], [1.3], "o")
  31.  
  32. function euler_iteration(armDiff, KM, DM, increment)
  33.     derivative = DM * armDiff + KM
  34.     derivative *= increment
  35.     return inv(DM) * (derivative - KM)
  36. end
  37.  
  38. h = 0.001
  39. r = 0:h:50
  40.  
  41. DM(a) = [0 1; -2*(1-a)  -1]
  42. KM(t) = [0; 0.3*sin(2*pi*t)]
  43.  
  44. aArm1 = guess[1]
  45. aArm2 = guess[2]
  46. arm1Diff = [pi/4;0.0]
  47. arm2Diff = [0.0;0.0]
  48.  
  49. iterations = 1
  50. for i in r
  51.     if iterations%100 == 1
  52.         angles = [arm1Diff[1], arm2Diff[1]]
  53.         arm1plotx = [0, a1x(angles)]
  54.         arm1ploty = [0, a1y(angles)]
  55.         arm2plotx = [a1x(angles), ax(angles)]
  56.         arm2ploty = [a1y(angles), ay(angles)]
  57.         plot(arm1plotx, arm1ploty)
  58.         plot(arm2plotx, arm2ploty)
  59.  
  60.         pause(0.1)
  61.     end
  62.  
  63.  
  64.     arm1Diff = euler_iteration(arm1Diff, KM(i), DM(aArm1), h)
  65.     arm2Diff = euler_iteration(arm2Diff, KM(i), DM(aArm2), h)
  66.  
  67.     iterations += 1
  68. end
  69.  
  70. println(arm1Diff)
  71. println(arm2Diff)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement