Skip to content

Instantly share code, notes, and snippets.

@DiamondLovesYou
Created October 25, 2016 15:35
Show Gist options
  • Save DiamondLovesYou/32ed8d19df503547e7544c23ceae3897 to your computer and use it in GitHub Desktop.
Save DiamondLovesYou/32ed8d19df503547e7544c23ceae3897 to your computer and use it in GitHub Desktop.
Problem 4.15

Problem 4.15

e415.m

abserr = 1e-8;
relerr = 1e-6;

figure;
fplot(@e415f);

b = 100;
c = 600;
  
[b,c,residual,flag] = Zero('e415f',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);
elseif flag ==  1
  fprintf('Too much work \n');
  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);

e415f.m

function y = e415f( x )
y = 21.1306 - 3480.3 / x - 5.081 * log10(x);
return

stdout:

e415

flag = 0 
Computed a root b = 4.569975e+02 
The residual f(b) = -2.411655e-07 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment