Advertisement
ruhan008

Regula Falsi

Aug 22nd, 2024
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.41 KB | None | 0 0
  1. function x = regulaFalsi(a, b, n)
  2.    
  3.     c = f(a);
  4.     d = f(b);
  5.  
  6.     if c * d > 0
  7.         error('The function has same sign on both the sides')
  8.     end
  9.  
  10.     for i = 1 : n
  11.        
  12.         if f(a) == f(b)
  13.             break;
  14.         end
  15.  
  16.         x = (a * f(b) - b * f(a)) / (f(b) - f(a));
  17.  
  18.         if f(x) < 0
  19.             a = x;
  20.         elseif f(x) > 0
  21.             b = x;
  22.         end
  23.  
  24.     end
  25. end
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement