Created
October 13, 2016 15:24
-
-
Save DiamondLovesYou/2996f03e05d4630bdd34badd7e7eca23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [ ] = E4_10helper( function_file ) | |
%E4_10HELPER Holds common code used in each part. | |
global nfeval | |
b = 1; | |
c = 0; | |
abserr = 1e-8; | |
relerr = 1e-6; | |
nfeval = 0; % global variable to count function evaluations. | |
figure | |
fplot(function_file, [0 1]) | |
grid on | |
title(function_file) | |
xlabel('x'); | |
ylabel('y'); | |
% Use Zero to find a root. | |
try | |
[b,c,residual,flag] = Zero(function_file,b,c,abserr,relerr); | |
% Check flag and print results. | |
fprintf('flag = %i \n',flag) | |
if flag == 0 | |
fprintf('Computed a root b = %e \n',b); | |
fprintf('%i evaluations of f were required. \n',nfeval); | |
elseif flag == 1 | |
fprintf('Too much work: nfeval = %i \n',nfeval); | |
fprintf('There is a root in [b,c] with \n'); | |
fprintf('b = %e, c = %e \n',b,c); | |
elseif flag == 2 | |
fprintf('Computed a pole b = %e \n',b); | |
end | |
fprintf('The residual f(b) = %e \n',residual); | |
catch error | |
fprintf('There are no roots in the bracket\n'); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment