Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
%ME3255 Homework 3
%Ryan Hyatt
%See README.m
%TODO - A better description.
clc
vmag = 5; %input initial speed.
height = 1.27; %target height.
y0 = 1.72; %the initial height of the projectile.
a = -9.81; %downward acceleration due to gravity.
delta_x = 2.37; %horizontal displacement
es = .00001;%accuracy?
dx = 10e-6;
maxiter = 10000;
xrold = 0;
guess = 25; % value of initial guess, if the function requires one.
thetas = linspace(15,65);
heights = ones(1,length(thetas));
i = 0;
for i = 1:length(thetas)
heights(i) = projectile(thetas(i), vmag)-height;
end
plot(thetas, heights)
for maxiter = 1:50
%Newton's method.
[root(maxiter,1),ea(maxiter,1),iter(1)] = newtraph(@(theta) projectile(theta, vmag) - height,...
@(theta) dprojectile_dtheta(theta, vmag),...
guess,es,maxiter); % 1
%False Position Method
xl = 0;
xu = 30;
[root(maxiter,2),fx,ea(maxiter,2),iter(2)]=falsepos(@(theta) (projectile(theta, vmag) - height)...
,xl,xu,es,maxiter); %2
%Bisect Method
[root(3),fx,ea(3),iter(3)]=bisect(@(theta) (projectile(theta, vmag) - height)...
,xl,xu,es,maxiter); %3
%Modified Secant
[root(maxiter,4),ea(maxiter,4),iter(4)]=mod_secant(@(theta) (projectile(theta, vmag) - height),...
dx,guess,es,maxiter); %4
end
ea
plot(ea)
title('Convergance');
xlabel('Iterations');
ylabel('ea');