-
Notifications
You must be signed in to change notification settings - Fork 0
/
solve_FHN_w.m
98 lines (80 loc) · 2.56 KB
/
solve_FHN_w.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
% - Solves FitzHugh Nagumo travelling wave equation
% - Requires optimization toolbox and external routines FHNeqn_w_periodic.m
% and fourdif.m
% Copyright (C) 2023 Paul Carter
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
%% setup
par.N = 1000; % number of mesh points, must be even!
par.L = 1000; % domain truncation
% spatial grid
N = par.N;
L = par.L;
par.h = L/(N-1); h = par.h;
x = (0:N-1)'*h;
%% initial conditions & parameters
% params1 [§8.1 Figure 6]
par.a = 0.0997212;
par.eps = 0.0021398784312;
par.gamma = 3.5;
load('initial_pulse_1');
c = 0.548;
lambdac0 = -0.0194;
par.eta = 0.0;
% % params2 [§8.2.1 Figure 7a]
% par.a = 0.167095;
% par.eps = 0.0021398784312;
% par.gamma = 0.5;
% load('initial_pulse_2');
% c = 0.4446;
% lambdac0 = -0.0408;
% par.eta = 0.1; % exponential weight for eigenvalue problem
% % params3 [§8.2.2 Figure 7b]
% par.a = 0.0058792294665;
% par.eps = 0.0021398784312;
% par.gamma = 0.5;
% load('initial_pulse_3');
% c = 0.6864;
% lambdac0 = -0.0374;
% par.eta = 0.1; % exponential weight for eigenvalue problem
U = Uout;
U0 = U;
%% solve nonlinear problem using fsolve
% option to display output and use Jacobian
options=optimset('Display','iter','Jacobian','on','MaxIter',100000,'Algorithm','levenberg-marquardt');
% call solve
[Uout,fval] = fsolve(@(U) FHNeqn_w_periodic(U,U0,par),U,options);
%% plot results
cout = Uout(end) % wave speed
figure(1);
plot(x,Uout(1:N));
xlabel('x');
ylabel('u');
title('Pulse on the line');
drawnow;
%% compute leading eigenfunction
[F,J,Jw] = FHNeqn_w_periodic(Uout,Uout,par);
[V1,DD1] = eigs(Jw,100,1);
evalsn = diag(DD1);
% manually extract critical eigenvalue/eigenfunction
eval_loc = find(abs(evalsn-lambdac0)<0.001);
lambdac = evalsn(eval_loc) % critical eigenvalue
v1 = V1(:,eval_loc);
u1 = real(v1(1:N));
figure(2);
plot(x,Uout(1:N));hold on;
plot(x,max(Uout(1:N))/max(abs(u1))*u1); hold off;
xlabel('x');
ylabel('u');
title('Critical eigenfunction in weighted space');