Commit bfe23ea8 authored by Gidon Lucian Bauer's avatar Gidon Lucian Bauer 🏳
Browse files

Central Finite Differences for Jacobian

parent 210bcaec
......@@ -8,10 +8,10 @@ function [jac] = jacobi(func, u, h)
ej = zeros(si,1);
ej(j) = 1;
fh = func(u + h.*ej);
f = func(u);
jac(i,j) = (fh(i) - f(i))/h;
% First derivative using central finite differences: O(h^2)
f_plus_h = func(u + h.*ej);
f_minus_h = func(u - h.*ej);
jac(i,j) = (f_plus_h(i) - f_minus_h(i)) / (2*h);
end
end
end
\ No newline at end of file
%% Calculates the maximal eigenvalue of Jacobian at ul and ur
function [ar] = max_eig(func, ul, ur)
h = 1e-8; % for numerical approximation of the jacobian
h = 1e-7; % for numerical approximation of the jacobian
si = length(ul);
......@@ -16,5 +16,5 @@ function [ar] = max_eig(func, ul, ur)
if ar > 1e5
ar = 1e5;
end
disp(ar);
% disp(ar);
end
\ No newline at end of file
%% Calculates the minimal eigenvalue of Jacobian at ul and ur
function [al] = min_eig(func, ul, ur)
h = 1e-8; % for numerical approximation of the jacobian
h = 1e-7; % for numerical approximation of the jacobian
si = length(ul);
......@@ -16,5 +16,5 @@ function [al] = min_eig(func, ul, ur)
if (al < -1e5)
al = -1e5;
end
disp(al);
% disp(al);
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment