Skip to content

Instantly share code, notes, and snippets.

Nick Higham higham

Block or report user

Report or block higham

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@higham
higham / complex_step_example.m
Last active Jan 1, 2019
Complex step example
View complex_step_example.m
% Complex step example. Requires Symbolic Math Toolbox.
format long
syms x; f = atan(x)/(1+exp(-x^2))
% Derivative at $a = 2$:
a = 2; fd = double(subs( diff(f), a))
% Convert symbolic function to MATLAB function.
f = matlabFunction(f);
@higham
higham / complex_step.m
Created Apr 21, 2018
Complex step approximation to derivative.
View complex_step.m
function fd = complex_step(f,x,h)
%COMPLEX_STEP Complex step approximation to derivative.
% fd = COMPLEX_STEP(f,x,h) computes the complex step approximation
% fd to the derivative of f at x, using step h (default 1e-100).
if nargin < 3, h = 1e-100; end
fd = imag( f(x + sqrt(-1)*h) )/h;
@higham
higham / ncm_compare.m
Created Feb 3, 2018
MATLAB expriment for correlation matrix compleition
View ncm_compare.m
%NCM_COMPARE
% M-file to carry out experiment in "Explicit Solutions to Correlation
% Matrix Completion Problems, with an Application to Risk Management and
% Insurance" by Dan I. Georgescu, Nicholas J. Higham and Gareth W. Peters.
C = [%
1 0.25 0.6 0.55 0.65 0 0.4 0.6 0.2 0.3
0.25 1 0 0 0 0 NaN NaN NaN NaN
0.6 0 1 0.75 0.75 0 NaN NaN NaN NaN
0.55 0 0.75 1 0.5 0 NaN NaN NaN NaN
@higham
higham / edelman.m
Last active Jun 14, 2018
MATLAB function producing Alan Edelman's matrix for which det is computed as the wrong integer.
View edelman.m
function A = edelman
%EDELMAN Alan Edelman's matrix for which det is computed as the wrong integer.
% A = EDELMAN is a 27-by-27 matrix of 1s and -1s for which the
% MATLAB det function returns an odd integer, though the exact
% determinant is an even integer.
A = [%
1 1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 1 -1 1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1
1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 1 -1 1 1 1
-1 1 -1 -1 1 1 1 1 1 -1 1 -1 1 1 1 1 -1 -1 1 -1 -1 1 1 -1 1 1 -1
@higham
higham / rel_err_formula.m
Last active Aug 6, 2017
MATLAB script to compare two formulas for relative error.
View rel_err_formula.m
%REL_ERR_FORMULA Compare two formulas for relative error.
n = 500;
a = 3;
x = a*ones(n,1,'single');
y = zeros(size(x));
d = eps(single(a));
for i=1:n
i-n/2
View funm_randomized
function F = funm_randomized(A,fun)
%FUNM_RANDOMIZED Evaluate general matrix function using
% randomized approximate diagonalization method of Davies (2007).
tol = 8*eps(A(1,1)); % Tolerance for single or double precision A.
E = randn(size(A));
[V,D] = eig(A + (tol*norm(A,'fro')/norm(E,'fro'))*E);
F = V*diag(fun(diag(D)))/V;
You can’t perform that action at this time.