annotate findZeros.m @ 577:e45c9b56d50d feature/grids

Add an Empty grid class The need turned up for the flexural code when we may or may not have a grid for the open water and want to plot that solution. In case there is no open water we need an empty grid to plot the empty gridfunction against to avoid errors.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 07 Sep 2017 09:16:12 +0200
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