Skip to content

Commit e2f3c6a

Browse files
committed
Made jacobian more optimal; other
Note: the jacobian is dense for all non-trivial inputs. for the initial condition it might seem like the jacobian is sparse, but this is a red herring. The jacobian is dense, and the way in which it is computed in this code is as efficient as I dare make it.
1 parent c7beadc commit e2f3c6a

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/+otp/+kuramotosivashinsky/KuramotoSivashinskyProblem.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,17 @@ function onSettingsChanged(obj)
2424

2525
L = obj.Parameters.L;
2626

27-
N = numel(obj.Y0);
27+
N = obj.NumVars;
2828

2929
div = L/(2*pi);
3030

3131
k = (1i*[0:(N/2 - 1), 0, (-N/2 + 1):-1].'/div);
3232
k2 = k.^2;
3333
k4 = k.^4;
34-
35-
Dfft = dftmtx(N);
36-
Difft = conj(Dfft)/N;
3734

3835
obj.Rhs = otp.Rhs(@(t, u) otp.kuramotosivashinsky.f(t, u, k, k2, k4), ...
3936
otp.Rhs.FieldNames.Jacobian, ...
40-
@(t, u) otp.kuramotosivashinsky.jac(t,u, k, k2, k4, Dfft, Difft), ...
37+
@(t, u) otp.kuramotosivashinsky.jac(t,u, k, k2, k4), ...
4138
otp.Rhs.FieldNames.JacobianVectorProduct, ...
4239
@(t, u, v) otp.kuramotosivashinsky.jvp(t,u, k, k2, k4, v));
4340

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function j = jac(~, u, k, k2, k4, Dfft, Difft)
1+
function j = jac(~, u, k, k2, k4)
22

3-
j = -diag(k2) - diag(k4) - diag(k)*Dfft*diag(ifft(u))*Difft;
3+
j = -diag(k2) - diag(k4) - diag(k)*ifft(fft(diag(ifft(u))).').';
44

55
end

0 commit comments

Comments
 (0)