Advertisement
TwentyEight

A551GNM3NT III

May 12th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.50 KB | None | 0 0
  1. clc
  2. clear all
  3. close all
  4.  
  5. vB = 8; %m/s of bowler's run
  6. lArm = 0.8; %m of arm
  7. hBall = 2.4; %m height of ball at release
  8. I = 0.64; %kgm^2 mass moment of inertia of the arm
  9. m = 160; %g of ball
  10. r = 55; %mm of ball
  11. lPitch = 20; %m of cricket pitch
  12. R = 0.8; %coefficient of resititution between ball and pitch
  13.  
  14. torq = input('The applied torque about the shoulder: ');
  15. angd = input('The angle with the horizontal axis at which the ball is released: ');
  16.  
  17. Wd = torq * 225 * (pi / 180); %Work done is equal to kinetic energy
  18. omega = sqrt(2 * Wd / I); %rotational velocity
  19. vbB = lArm * omega; %velocity of ball relative bowler
  20.  
  21. %Using Cosine Rule; calculating coefficients for vb terms
  22. A = 1;
  23. B = -2*vB*cosd(angd);
  24. C = vB^2 - vbB^2;
  25. rootsvb = roots([A B C]);
  26. for index1 = 1: numel(rootsvb);
  27.     if isreal(rootsvb(index1))&&rootsvb(index1)>0
  28.         vb = rootsvb(index1);
  29.         break
  30.     end
  31. end
  32.  
  33. %Using Euler's Method
  34. tFinal = 20 / (vb*cosd(-angd)); %horizontal velocity remains constant
  35. %Total time to reach 20metres can be calculated
  36. num = 600; %Number of individual points on the plot
  37. %Increase num to increase accuracy, but plot takes longer to draw
  38. t = linspace(0, tFinal, num); %Vector of equally spaced time intervals
  39. deltaT = tFinal / num; %Distance between each time interval; smaller is more accurate
  40. a = [0; -9.81]; %Acceleration remains constant throughout
  41. v(:, 1) = [vb*cosd(-angd); vb*sind(-angd)]; %Components of initial velocity
  42. x(:, 1) = [0; hBall]; %Components of initial displacement
  43.  
  44. %Creating animated plot
  45. figure
  46. h = animatedline;
  47. ax = gca;
  48. ax.XAxisLocation = 'origin';
  49. xlabel('Distance (metres)');
  50. ylabel('Height (metres)');
  51.  
  52. axis([0 lPitch+1 -0.5 2.5])
  53. %Creating a for loop to generate displacements for each time point
  54. for ind = 1:num
  55.     %Calculating the next displacement vector
  56.     x(:, ind+1) = x(:, ind) + v(:, ind)*deltaT;
  57.     if x(2, ind+1) > 0 %Checks if the ball is still in the air
  58.         %Calculating the next velocity vector
  59.         v(:, ind+1) = v(:, ind) + a*deltaT;  
  60.     else %The ball is in contact with the ground
  61.         x(2, ind+1) = 0; %Defining the j component of displacement as 0
  62.         %Calculating the j component of next velocity vector using
  63.         %restitution
  64.         v(:, ind+1) = [v(1, ind); -R*v(2, ind)+a(2)*deltaT];
  65.     end
  66.    
  67.     %Drawing the next displacement vector
  68.     addpoints(h,x(1, ind+1),x(2, ind+1));
  69.     drawnow
  70.    
  71.     if x(1,ind+1) > 20 %If the distance is past 20 metres; the loop will stop
  72.         break
  73.     end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement