comparison findZeros.m @ 820:501750fbbfdb

Merge with feature/grids
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 07 Sep 2018 14:40:58 +0200
parents 8368beb0d1b3
children
comparison
equal deleted inserted replaced
819:fdf0ef9150f4 820:501750fbbfdb
1 % findZeros looks for solutions to the equation f(x)==0 within
2 % the limits lim with a granularity of h.
3 % Returns a sorted list of unique solutions.
4 function z = findZeros(f, lim, h)
5 n = ceil((lim(2)-lim(1))/h);
6 z0 = linspace(lim(1), lim(2), n);
7
8 z = zeros(1,n);
9
10 for i = 1:n
11 zt(i) = fzero(f, z0(i));
12 end
13
14 zt = sort(zt);
15
16 z = [];
17 for i = 1:n
18 if zt(i) < lim(1) || zt(i) > lim(2)
19 continue
20 end
21
22 if ~isempty(z) && abs(z(end) - zt(i)) < 1e-6
23 continue
24 end
25
26 z = [z zt(i)];
27 end
28
29 % z = unique(z);
30 end