annotate findZeros.m @ 774:66eb4a2bbb72 feature/grids

Remove default scaling of the system. The scaling doens't seem to help actual solutions. One example that fails in the flexural code. With large timesteps the solutions seems to blow up. One particular example is profilePresentation on the tdb_presentation_figures branch with k = 0.0005
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 18 Jul 2018 15:42:52 -0700
parents 8368beb0d1b3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
306
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
1 % findZeros looks for solutions to the equation f(x)==0 within
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
2 % the limits lim with a granularity of h.
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
3 % Returns a sorted list of unique solutions.
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
4 function z = findZeros(f, lim, h)
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
5 n = ceil((lim(2)-lim(1))/h);
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
6 z0 = linspace(lim(1), lim(2), n);
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
7
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
8 z = zeros(1,n);
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
9
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
10 for i = 1:n
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
11 zt(i) = fzero(f, z0(i));
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
12 end
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
13
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
14 zt = sort(zt);
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
15
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
16 z = [];
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
17 for i = 1:n
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
18 if zt(i) < lim(1) || zt(i) > lim(2)
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
19 continue
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
20 end
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
21
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
22 if ~isempty(z) && abs(z(end) - zt(i)) < 1e-6
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
23 continue
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
24 end
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
25
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
26 z = [z zt(i)];
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
27 end
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
28
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
29 % z = unique(z);
8368beb0d1b3 Added function to calculate multiple solutions to an equation.
Jonatan Werpers <jonatan@werpers.com>
parents:
diff changeset
30 end