Mercurial > repos > public > sbplib
comparison findZeros.m @ 306:8368beb0d1b3 feature/beams
Added function to calculate multiple solutions to an equation.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 22 Sep 2016 09:34:27 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
305:dfa4455033db | 306:8368beb0d1b3 |
---|---|
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 |