Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 13th, 2013  |  syntax: MatLab  |  size: 0.98 KB  |  views: 29  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function cpendula (th1,th2,k,t,ti,d,m,l)
  2. dt=t/ti; x1=(0:t/ti); x2=(0:t/ti); v1=(0:t/ti); v2=(0:t/ti);
  3. x1(1)=th1; %set initial position to given thete coordinate x2(1)=th2;
  4. thetaAccel1(theta1,theta2)=(k/(ml2))(d-sqrt(ll(cos(theta1)-cos(theta2))2))((l2(cos(theta1)-cos(theta2))sin(theta1))-lcos(theta1)(d+lsin(theta2)-lsin(theta1)))/sqrt(l2(cos(theta1)-cos(theta2)2)+(d+lsin(theta2)-lsin(theta1))2)-mgl*sin(theta1);
  5. thetaAccel2(theta1,theta2)=(k/(ml2))(d-sqrt(ll(cos(theta1)-cos(theta2))2))((l2(cos(theta1)-cos(theta2))sin(theta2))-lcos(theta2)(d+lsin(theta2)-lsin(theta1)))/sqrt(l2(cos(theta1)-cos(theta2)2)+(d+lsin(theta2)-lsin(theta1))2)-mgl*sin(theta2);
  6. %Need to have the inputs be initial theta, spring constant, initial %velocity.
  7. for f= 2:ti;
  8. v1(f)=v1(f-1)+thetaAccel1(x1(f-1),x2(f-1))*dt;
  9. v2(f)=v2(f-1)+thetaAccel2(x1(f-1),x2(f-1))*dt;
  10.  
  11. x1(f)=x1(f-1)+v1(f-1)*dt+.5*thetaAccel1(x1(f-1),x2(f-1))*dt^2;
  12. x2(f)=x2(f-1)+v2(f-1)*dt+.5*thetaAccel2(x1(f-1),x2(f-1))*dt^2;
  13. end
  14. plot(x1,dt);
  15. end
clone this paste RAW Paste Data