Guest User

Untitled

a guest
Oct 29th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.45 KB | None | 0 0
  1. clear all
  2. %Please read comments at bottom - Thank you!
  3.  
  4. %Initial Values ---
  5. mass = 0.43;%kg
  6. circum = 0.69;%m
  7. radius = circum/(6.28);% Rad = cirumference/2*pi
  8. A = (pi)*radius^(2);%Calculating the cross sectional area from the radius
  9. rho = 1.22;%kg/m^3
  10. C_pd = 0.3;%Drag Coefficient
  11.  
  12. phi = input('Enter the angle between the x axis and velocity vector - from 0 to pi/2 radians' );
  13. theta = input('Enter the angle between the xy-plane and velocity vector (vertical angle) - from 0 to pi/2 radians');
  14. vnorm = 30;%This is the norm of v, the initial speed
  15. vx = vnorm*cos(theta)*cos(phi); %initial x velocity in terms of the input angles and the norm
  16. vy = vnorm*cos(theta)*sin(phi); %intitial y velocity in terms of the input angles and the norm
  17. vz = vnorm*sin(theta); % initial z velocity in terms of the input angles and the norm
  18.  
  19.  
  20. v = [vx vy vz];%Instantiating the velocity vector
  21. omega = [0 0 10];%The rotation is 10 rads/s around the z axis
  22. accel = [0  0  0]; %Instantiating the acceleration vector
  23. r = [0 0 0]; %The position vector - the ball is initially at the origin
  24. f = [v(1),v(2),v(3),accel(1),accel(2),accel(3)]; %We use the velocity and acceleration vectors to create a state vector
  25. F_pd = -0.5*rho*C_pd*A*vnorm*v;%This is the equation for drag force
  26. F_l = rho*radius^(3)*cross(omega,v);%Here we have our equation for the lift force
  27. n = 10000; %here is our step max
  28. time = 0; %Setting up our initial time in seconds
  29. tau = .1; %Our time step is 1 second
  30.  
  31. %Now we will set up our runge kutta integration loop & boundary conditions
  32.  
  33.  
  34. for i = 1:n %our iterative interval
  35.     accel = (1/mass)*(F_pd) + (1/mass)*(F_l);%Here I have acceleration in the loop in order to update our vmid(which we will need in accel mid and thus in v and in our determination of r)
  36.     vmid =  v + tau*accel/2;%Our velocity midpoint
  37.     accelmid = (1/mass)*(-0.5*rho*C_pd*A*vnorm*vmid) + (1/mass)*(rho*radius^(3)*cross(omega,vmid)); %Here we are utilizing vmid to establish a midpoint for our acceleration function which we can use in the RK2 procedure to update our velocity
  38.     v = v + tau*accelmid/2;%Here we are updating the velocity using the mid point acceleration
  39.     r = r + tau*vmid/2; %Here we are updating our position vector using the midpoint velocity
  40.     x = r(1); %Attempt at dummy variable for x
  41.     y = r(2);
  42.     z = r(3);
  43.     dummyx = x(i);
  44.     dummyy = y(i);
  45.     dummyz = z(i);
  46.     time = time + tau; %Here we have our time advancing by 1 second each iteration thus giving us n second on our plot
  47.     if ((r(1) < 0) || (r(1) > 105))%If the ball leaves out the left or right side of the field...
  48.         disp('The ball has left the field');%Say that and..
  49.         break %Stop the loop
  50.     elseif (( r(2) < 0) || (r(2) > 68))%If the ball leaves the top or bottom of the field...
  51.         print('The ball has left the field');%Say that and...
  52.         break %Stop the loop
  53.     elseif (r(3) < 0)%If the ball hits the ground after being kicked and before reaching the goal...
  54.         print('The ball did not make it to the goal')%Say that and...
  55.         break %Stop the loop
  56.     elseif ((r(1) == 0) && ((r(2) > 30.34)&&(r(2) < 37.66)) && (r(3) < 2.44))%If the ball reaches the goal area...
  57.         disp('Goooooaaaaaaaalllllllllllll!!!');%Say that and...
  58.         disp(phi) %Return the value of phi which lead to your goal
  59.         disp(theta) %Return the value of theta which lead to the goal
  60.         break
  61.     end
  62. end
  63.  
  64.  
  65. figure(1);
  66. hold on
  67. plot3(dummyx,dummyy,dummyz,'*r');
Add Comment
Please, Sign In to add comment