Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Written by: Taylor Poon, ID: 30750539
- %Created: 18/09/19
- %ball trajectory using secant method
- clear all; close all; clc;
- %variables
- % v0 = initial velocity
- % y0 = thrower's elevation
- % x = distance from the thrower to the catcher
- % y = catcher's elevation
- % tangle = throwing angle
- % ptangle = angle previous to throwing angle
- % g = gravitational acceleration
- % precision = precision used to decide if value is close enough to the root
- v0 = 20;
- y0 = 2;
- x = 35;
- y = 1;
- g = 9.81;
- %trajectory of a thrown ball anonymous function
- theta = linspace(0,60);
- f = @ (theta) tand(theta).*x - g ./ (2*v0^2.*cosd(theta).^2) * x^2 + y0 - y;
- %call secant function
- xi = 15;
- xi_1 = 60;
- precision = 1e-4;
- [root, iter] = secant(f,xi,xi_1, precision);
- plot(theta, f(theta));
- title('angle of thrown ball trajectory');
- xlabel('theta (degrees)');
- ylabel('thrown ball trajectory equation');
- hold on
- plot(root,f(root), 'kd');
- fprintf('The initial throwing angle required is %2.f degrees and the number of iterations taken is %2.f.', root, iter);
- %plot root-finding equation
- % df = @ (theta) tand(theta) - g ./ (v0^2 .* cosd(theta).^2) * x;
- % [root_min, iter_min] = secant(df, xi, xi_1, precision);
- % hold on
- % root_min %check this, maybe equation is wrong?
- % plot(root_min,f(root_min), 'bd');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement