Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. clear; clc
  2. % Bike Project Model
  3.  
  4. % Define Constants
  5. m = 5.97; % Slugs
  6. I = 1; % THIS NEEDS TO BE CHANGED
  7. k = 325*12; % Spring rate constant lbf/ft
  8. c = sqrt(k*m); % Spring damper constant lbf/ft
  9. wheelD = 29/12; % Diameter of wheel inches/12 (ft)
  10. g = 32.2; % ft/s^2
  11. SLxo = 0; % Initial length of shock in x-direction
  12. SLyo = 1; % Initial length of shock in y-direction
  13. track = @(t) sin(t); % Bike track
  14. theta = deg2rad(0);
  15.  
  16. % Define the ODE
  17.  
  18. % ODE in x-direction
  19. fx = @(t,SLx,Vx) Vx; % Velocity of shock in x-direction (dx/dt)
  20. fVx = @(t,SLx,Vx) -k/m*(SLx-SLxo)-c/m*Vx; % Acceleration of shock in x-direction (d^2x/dt^2)
  21.  
  22. % ODE in y-direction
  23. fy=@(t,SLy,Vy) Vy; % Velocity of shock in y-direction (dy/dt)
  24. fVy=@(t,SLy,Vy) -k/m*(SLy-SLyo)-c/m*Vy; % Acceleration of shock in y-direction (d^2y/dt^2)
  25.  
  26. % ODE in angular direction
  27. % ##########
  28. % ##########
  29.  
  30. % Domain size
  31. trackLength = 5*pi; % Track length
  32. h = .01; % Step-size
  33.  
  34. % Number of steps
  35. N = round(trackLength/h); % Calculates number of steps
  36.  
  37. % Preallocate
  38. t = zeros(1,N); % Time array
  39. x = zeros(1,N); % Velocity in x-direction array
  40. Vx = zeros(1,N); % Acceleration in x-direction array
  41. y = zeros(1,N); % Velocity in y-direction array
  42. Vy = zeros(1,N); % Acceleration in y-direction array
  43.  
  44. % Initial Conditions
  45. t(1) = 0; % Starts at time 0
  46. SLx(1) = 0; % Initial shock length in the x-direction
  47. Vx(1) = 0; % Initial velocity in the x-direction
  48. SLy(1) = 1; % Initial shock length in the y-direction
  49. Vy(1) = 0; % Initial velocity in the y-direction
  50.  
  51. % Loop over time
  52. for i=1:N-1
  53. t(i+1) = t(i)+h;
  54. Ls(i+1) = shock_length(t(i),SLyo,theta,track,wheelD); % shock length at each step
  55. Lsx(i+1) = Ls(i)*sin(theta); % Length of shock in x-direction
  56. Lsy(i+1) = Ls(i)*cos(theta); % Length of shock in y-direction
  57. x(i+1) = x(i)+h*fx(t(i),SLx(i),Vx(i));
  58. Vx(i+1) = Vx(i)+h*fVx(t(i),SLx(i),Vx(i));
  59. y(i+1) = y(i)+h*fy(t(i),SLy(i),Vy(i));
  60. Vy(i+1) = Vy(i)+h*fVy(t(i),SLy(i),Vy(i));
  61. end
  62.  
  63. % Plot the solution
  64. figure (1); clf(1)
  65. plot(t,x)
  66. hold on
  67. plot(t,Vx)
  68. plot(t,y)
  69. plot(t,Vy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement