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
%HW_3
%Script calls functions and outputs tables and plots relevant to HW3.
[root1,fx1,ea1,iter1]=falsepos(@(x) projectile(x),1,50,.00001);
[root2,ea2,iter2]=mod_secant(@(x) projectile(x),1,50,.00001);
[root3, ea3, iter3]= newtraph(@(x) projectile(x),@(x) dprojectile_dtheta(x),50,.00001,1000);
[root4,fx4,ea4,iter4]=bisect(@(x) projectile(x),0,50,.00001);
%Question 1: part (i)
%for loop creates data table for given outputs above
for n=1:4;
Table(n,1)=root(n);
Table(n,2)=ea(n);
Table(n,3)=iter(n);
Table(n,4)=fx(n);
end
%Question 1: part(ii)
%Plots the graphs that compare methods
e_b = 1;
e_f = 2;
e_n = 3;
e_m = 4;
for n = 1:iter1
[r, y, e_b(n), k] = falsepos(@(x) projectile(x),1,50,.00001);
end
for n = 1:iter2
[r, y, e_f(n)] = mod_secant(@(x) projectile(x),1,50,.00001);
end
for n = 1:iter3
[r, e_n(n), k] = newtraph(@(x) projectile(x),@(x) dprojectile_dtheta(x),50,.00001,1000);
end
for n = 1:iter4
[r, e_m(n), k] = bisect(@(x) projectile(x),0,50,.00001);
end
%Plot
%This section sets up the code inorder to plot the data.
setdefaults
plot(1:iter1, e_b, 'g', 1:iter2, e_f, 'b', 1:iter3, e_n, 'r', 1:iter4, e_m, 'y')
title('Approx Err. of Convergent Functions vs Number of Iterations');
xlabel('Iteration');
ylabel('Approx Error');
legend('bisect','falsepos', 'newtraph', 'mod secant');