changeset 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 dfa4455033db
children fefb2f9884f7
files findZeros.m
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
diff -r dfa4455033db -r 8368beb0d1b3 findZeros.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/findZeros.m	Thu Sep 22 09:34:27 2016 +0200
@@ -0,0 +1,30 @@
+% 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
\ No newline at end of file