rorschack

QT_Prac_RegulaFalsi_1B

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