Guest User

Untitled

a guest
Oct 18th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. %Get the input for the function and the convergence criteria
  2. sfnc = input('Enter the function : ', 's');
  3. fnc = inline(sfnc, 'x');
  4. criteria = input('Enter the convergence criteria : ');
  5. fa = 1;
  6. fb = 1;
  7.  
  8. %Decide on an interval using input and checking whether a root definitely
  9. %exists within it
  10. while ((fa*fb) > 0) %loops while the statement is false, when true it stops
  11. %and the message below is displayed in the if statement.
  12. a = input('Enter the lower limit of the interval : ');
  13. b = input('Enter the upper limit of the interval : ');
  14. fa = fnc(a);
  15. fb = fnc(b);
  16. x1=a;
  17. x2=b;
  18.  
  19. xtrue = fzero(fnc, [b a]); %determines the true root of the function between [a,b]
  20.  
  21. clc
  22. if ((fa*fb) > 0)
  23. display('Please enter an interval such that f(a)*f(b) is negative.');
  24. end;
  25. end
Add Comment
Please, Sign In to add comment