Voldemord

Matlab-F-Sieczne

Mar 20th, 2019
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.67 KB | None | 0 0
  1. function [ x0 ] = sieczna( f, x1, x2 )
  2. f1 = f(x1);
  3. f2 = f(x2);
  4. E = 0.0001;
  5.  
  6.     for i=64:-1:0
  7.        if abs(x1-x2) > E
  8.            if abs(f1-f2) < E
  9.                disp('Zle punkty startowe');
  10.                break;
  11.            else
  12.                x0 = x1-f1*(x1-x2)/(f1-f2);
  13.                f0 = f(x0);
  14.                
  15.                if abs(f0) < E
  16.                    break;
  17.                else
  18.                   x2 = x1;
  19.                   f2 = f1;
  20.                   x1 = x0;
  21.                   f1 = f0;
  22.                end
  23.            end
  24.        else
  25.            break;
  26.        end
  27.     end
  28.     if i <= 0;
  29.         disp('Przekroczono limit obiegow');
  30.     end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment