...
 
Commits (2)
function [ root, xit, n ] = bisect( eq, min, max, precision )
%BISECT Returns the root value of a function by bisection method
%
% Params:
% eq - Equation
% min -
% min -
% precision - Maximum precision
%
% Example use:
% [int, remainder] = divr(26,2)
n = 0;
mid = (min + max) / 2;
xit = mid;
% Vorzeichenwechsel Test
if eq(min) * eq(max) > 0
root = "Keine Nullstelle";
% Abbruchkriterium
elseif abs(max - min) < precision
root = mid;
elseif eq(min) * eq(mid) <= 0
[root, xit, n] = bisect(eq, min, mid, precision);
elseif eq(mid) * eq(max) <= 0
[root, xit, n] = bisect(eq, mid, max, precision);
end
xit = [mid xit];
n = n + 1;
end
\ No newline at end of file
function [ o ] = fiterate(eq, start, precision)
%FITERATE Fix-point iteration
%
% Params:
% eq - Equation
% start - Starting value
% precision - Precision of result
%
% Usage:
% eq = @(x) x.^3 + 0.3
% fiterate(eq, -1, 0.0001)
o = eq(start);
if(abs(abs(start) - abs(o)) > precision)
o = fiterate(eq, o, precision);
end
end