Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Octave / bisection

.m
Скачиваний:
22
Добавлен:
18.08.2022
Размер:
1 Кб
Скачать
## Copyright (C) 2021 Lenovo
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <https://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {} {@var{retval} =} bisection (@var{input1}, @var{input2})
##
## @seealso{}
## @end deftypefn

## Author: Lenovo <Lenovo@DESKTOP-EIHPQD9>
## Created: 2021-10-24

function F = bisection(f,a,b,e)
  if (a > b || e < 0)
    F = 'Неверные даннные';
    return;
  else
    fa = f(a);
    fb = f(b);
    if (fa * fb < 0)
      while(true)
        fa = f(a);
        c = (a + b) *0.5;
        fc = f(c);
        if (abs(fc) < e )
          break;
        else
          if (fa * fc < 0)
            b = c;
          else
            a = c;
          endif
        endif
      endwhile
    else
      F = 'Неверные данные';
      return;
    endif
  endif
  F = c;
endfunction
Соседние файлы в папке Octave