annotate findZeros.m @ 1031:2ef20d00b386 feature/advectionRV

For easier comparison, return both the first order and residual viscosity when evaluating the residual. Add the first order and residual viscosity to the state of the RungekuttaRV time steppers
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 17 Jan 2019 10:25:06 +0100
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