view findZeros.m @ 888:8732d6bd9890 feature/timesteppers

Add general Runge-Kutta class - Add a general Runge-Kutta class which time integrates the solution based on coefficients obtained from a Butcher tableau - Add butcher tableau which returns coefficents for the specified Runge-Kutta method - Remove RungKutta4proper, since obsolete
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 15 Nov 2018 17:10:01 -0800
parents 8368beb0d1b3
children
line wrap: on
line source

% findZeros looks for solutions to the equation f(x)==0 within
% the limits lim with a granularity of h.
% Returns a sorted list of unique solutions.
function z = findZeros(f, lim, h)
    n = ceil((lim(2)-lim(1))/h);
    z0 = linspace(lim(1), lim(2), n);

    z = zeros(1,n);

    for i = 1:n
        zt(i) = fzero(f, z0(i));
    end

    zt = sort(zt);

    z = [];
    for i = 1:n
        if zt(i)  < lim(1) || zt(i) > lim(2)
            continue
        end

        if ~isempty(z) && abs(z(end) - zt(i)) < 1e-6
            continue
        end

        z = [z zt(i)];
    end

    % z = unique(z);
end