-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind_initial_condition.m
176 lines (132 loc) · 4.22 KB
/
find_initial_condition.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
function [start, dists_c1, dists_c2] = find_initial_condition(line, angle, arclength, modelpar, featpar,feature_handle, obj_handle)
% The function searches for an initial point and direction for
% continuation.
%
% Required input:
%
% line: a struct with two attributes line.start and line.end specifying the start and end points in
% the 2D parameter space.
%
% angle: a struct with two attributes angle.start and angle.end specifying
% the start and end of angle for the direction search.
%
% arclength: resolution of the search, should be consistent with
% continuation
path(path,'../Models/Reaction_Diffusion');
path(path,'../Models/Spiral_Wave');
% featpar.N = 1;
p_left = line.start;
p_right = line.end;
modelpar.a = p_left(1);
modelpar.b = p_left(2);
featuresl = feature_handle(featpar, modelpar);
if iscell(featuresl)
featuresl = featuresl{1};
end
modelpar.a = p_right(1);
modelpar.b = p_right(2);
featuresr = feature_handle(featpar, modelpar);
if iscell(featuresr)
featuresr = featuresr{1};
end
search_1 = [];
dists_c1 = [];
% First do a bisection to find the starting point
while norm(p_right - p_left) >= .1*arclength
p_mid = 0.5*( p_left + p_right );
modelpar.a = p_mid(1);
modelpar.b = p_mid(2);
featuresm = feature_handle(featpar, modelpar);
if iscell(featuresm)
featuresm = featuresm{1};
end
obj_l = obj_handle(featuresm,featuresl);
search_1 = [search_1, 0.5*(p_left + p_mid)' ];
dists_c1 = [dists_c1, obj_l/norm(p_left-p_mid)];
obj_r = obj_handle(featuresm,featuresr);
search_1 = [search_1, 0.5*(p_right + p_mid)' ];
dists_c1 = [dists_c1, obj_r/norm(p_right-p_mid)];
if obj_l > obj_r
p_right = p_mid;
featuresr = featuresm;
else
p_left = p_mid;
featuresl = featuresm;
end
end
start.point = p_mid;
% Then search for the optimal direction
% angles = linspace(angle.start,angle.end,num_search);
angle_left = angle.start;
angle_right = angle.end;
modelpar.a = start.point(1) + arclength*cos(angle_left);
modelpar.b = start.point(2) + arclength*sin(angle_left);
featuresl = feature_handle(featpar, modelpar);
if iscell(featuresl)
featuresl = featuresl{1};
end
modelpar.a = start.point(1) + arclength*cos(angle_right);
modelpar.b = start.point(2) + arclength*sin(angle_right);
featuresr = feature_handle(featpar, modelpar);
if iscell(featuresr)
featuresr = featuresr{1};
end
search_2 = [];
dists_c2 = [];
while norm(angle_right - angle_left) >= pi/8
angle_mid = 0.5*( angle_left + angle_right );
modelpar.a = start.point(1) + arclength*cos(angle_mid);
modelpar.b = start.point(2) + arclength*sin(angle_mid);
featuresm = feature_handle(featpar, modelpar);
if iscell(featuresm)
featuresm = featuresm{1};
end
obj_l = obj_handle(featuresm,featuresl);
search_2 = [search_2, start.point'+arclength*[cos(0.5*(angle_left + angle_mid)');sin(0.5*(angle_left + angle_mid))] ];
dists_c2 = [dists_c2, obj_l];
obj_r = obj_handle(featuresm,featuresr);
search_2 = [search_2, start.point'+arclength*[cos(0.5*(angle_right + angle_mid)');sin(0.5*(angle_right + angle_mid))] ];
dists_c2 = [dists_c2, obj_r];
if obj_l > obj_r
angle_right = angle_mid;
featuresr = featuresm;
else
angle_left = angle_mid;
featuresl = featuresm;
end
end
angle_mid = 0.5*( angle_left + angle_right );
%idx = find(dists_c2 == max(dists_c2)); %idx = idx( round(length(idx)/2));
start.normal = [cos(angle_mid),sin(angle_mid)];
figure(19);
scatter( search_1(1,:), search_1(2,:), [], dists_c1 , 'filled' )
hold on,
scatter( search_2(1,:), search_2(2,:), [], dists_c2 , 'filled' )
switch modelpar.model
case 'Brusselator'
ylim([6,13])
xlim([3,7])
xlabel('a')
ylabel('b')
case 'SH'
ylim([0,2])
xlim([-0.15,0.4])
xlabel('\mu')
ylabel('\nu')
case 'GS'
xlim([0.035,0.065])
ylim([0.005,0.06])
ylabel('f')
xlabel('k')
case 'Schnakenberg'
xlim([4.5,7.5]);
ylim([4.5,6.5]);
xlabel('a')
ylabel('b')
case 'Bullara'
xlim([0,4])
ylim([0,20])
xlabel('l_x')
ylabel('h')
end
set(gca,'fontsize',24);