rorschack

QT_Prac_Bisection_1A

Mar 1st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.32 KB | None | 0 0
  1. /*
  2. f(x) = x^3-x-2
  3. a = 1
  4. b = 2
  5.  
  6. Ans:
  7.    1.5
  8.  
  9.    1.75
  10.  
  11.    1.625
  12.  
  13.    1.5625
  14.  */
  15.  
  16. function[] = bisection(f);
  17. a=input('Value of a: ')
  18. b=input('Value of b: ')
  19. if(f(a)*f(b)<0)
  20. for i=1:4
  21. x=(a+b)/2;
  22. if(f(x)*f(b)<0)
  23. a=x;
  24. else
  25. b=x;
  26. end
  27. disp(x);
  28. end
  29. end
  30. endfunction;
  31.  
  32. deff('y=f(x)',['y=x^3-x-2'])
  33.  
  34. bisection(f)
Add Comment
Please, Sign In to add comment