Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. %Written by: Taylor Poon, ID: 30750539
  2. %Created: 18/09/19
  3. %ball trajectory using secant method
  4. clear all; close all; clc;
  5.  
  6. %variables
  7. % v0 = initial velocity
  8. % y0 = thrower's elevation
  9. % x = distance from the thrower to the catcher
  10. % y = catcher's elevation
  11. % tangle = throwing angle
  12. % ptangle = angle previous to throwing angle
  13. % g = gravitational acceleration
  14. % precision = precision used to decide if value is close enough to the root
  15. v0 = 20;
  16. y0 = 2;
  17. x = 35;
  18. y = 1;
  19. g = 9.81;
  20.  
  21.  
  22. %trajectory of a thrown ball anonymous function
  23. theta = linspace(0,60);
  24. f = @ (theta) tand(theta).*x - g ./ (2*v0^2.*cosd(theta).^2) * x^2 + y0 - y;
  25.  
  26. %call secant function
  27. xi = 15;
  28. xi_1 = 60;
  29. precision = 1e-4;
  30.  
  31. [root, iter] = secant(f,xi,xi_1, precision);
  32.  
  33. plot(theta, f(theta));
  34. title('angle of thrown ball trajectory');
  35. xlabel('theta (degrees)');
  36. ylabel('thrown ball trajectory equation');
  37. hold on
  38. plot(root,f(root), 'kd');
  39. fprintf('The initial throwing angle required is %2.f degrees and the number of iterations taken is %2.f.', root, iter);
  40.  
  41. %plot root-finding equation
  42. % df = @ (theta) tand(theta) - g ./ (v0^2 .* cosd(theta).^2) * x;
  43. % [root_min, iter_min] = secant(df, xi, xi_1, precision);
  44. % hold on
  45. % root_min %check this, maybe equation is wrong?
  46. % plot(root_min,f(root_min), 'bd');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement