# Defining a function for the construction of a bordered hessian

I think in Mathematica the omission of a function that can create a bordered matrix. This code works

m = {{a, b}, {c, d}};
k = {α, β}
l1 = Insert[ k, 0, 1];
c1 = Insert[Transpose[m], k, 1] // Transpose;
m1 = Insert[c1, l1, 1];
m1 // MatrixForm


and gives

$\begin{pmatrix} 0 & \alpha & \beta\\ \alpha & a & b\\ \beta & c & d \end{pmatrix}$

as expected.

So I have tried to design a function. But obviously it doesn't work

bordhess[mat_?MatrixQ[mat], vec_?VecQ[vec] ] :=
Block[{x = mat, y = vec},
l1 = Insert[ y, 0, 1];
c1 = Insert[Transpose[x], k, 1] // Transpose;
Insert[c1, l1, 1]
]


and even If I have been able to create such a function, I wonder how to generalize the problem to many vectors.

• ArrayFlatten[{{0, {k}}, {Transpose@{k}, m}}] Jan 18 '17 at 9:10
• Thanks too much simple for my complicated mind! Jan 18 '17 at 9:18
• @SimonRochester You should make this an answer :) Jan 18 '17 at 10:07

Also,

borderF = ArrayReshape[{0, #, Transpose[{##}]}, 1 + Dimensions@#2] &;

mat = Array[Subscript[a, ##] &, {4, 4}];
multipliers = Array[Subscript[λ, #] &, 4];
borderF[multipliers, mat] // MatrixForm • Does this do the multi-row block-bordering shown in the last images of Simon's and my answers? I believe that's what the OP is asking about (when wondering "how to generalize the problem to many vectors"), but I could be wrong. Jan 19 '17 at 1:58
• @MichaelE2, no it doesn't handle multi-row borders. Still trying to figure out the appropriate argument for ArrayReshape to get multi-row borders.
– kglr
Jan 19 '17 at 2:14
• @cyrcyrille.piatecki , i suppose the Accept is a mistake:) considering the generality and elegance of Simon's and Michal's answers.
– kglr
Jan 19 '17 at 3:00
• Of course, I have checked yours as I could have checked an other because all were satisfying I should have checked the more elegant but I do not know <hich is the one. Perhaps we could ask for the possibility to multi check some time. Jan 19 '17 at 12:38

You can do this with ArrayFlatten. Here is a generalization to one or more vectors -- I'm not sure if it's what you're looking for:

bordhess[mat_?MatrixQ, mat1_?MatrixQ] := ArrayFlatten[{{0, mat1}, {Transpose@mat1, mat}}]

bordhess[mat_?MatrixQ, vec_?VectorQ] := bordhess[mat, {vec}]


Then you have

m = {{a, b}, {c, d}};
k = {α, β};
j = {γ, δ};

bordhess[m, k] // MatrixForm bordhess[m, {k, j}] // MatrixForm Here's an answer to the title question, about constructing a bordered Hessian, in case someone come looking for answer to it. It comes directly from calculus, instead of playing with matrices.

Basically thus:

D[f + λ.g, {{λ1, λ2,..., x1, x2,...}, 2}]


where

λ = {λ1, λ2,...}


are the Lagrange multipliers and

x = {x1, x2,...}


are the variables of f and g.

Example:

ClearAll[bH];
bH[f_, g_List, x_List, param_: K] := bH[f, g, x, Array[param, Length@g]];
bH[f_, g_List, x_List, λ_List] := D[f + λ.g, {Join[λ, x], 2}];

bH[w^4 x + x^3 y + y^2 z + z^4,
{w^2 + x^2 + y^2 + z^2, w^2 + 2 x^2 + 3 y^2 + 4 z^2},
{w, x, y, z}, {λ, μ}] // MatrixForm • Bordered Hessian can also be used in checking quasi-concavity Jan 19 '17 at 12:40
• @cyrille.piatecki Yes, second derivatives are useful. (I'm not sure why the comment, actually. I suppose you mean specializing at bH[f, {f}, {x, y,..}, {λ}] /. λ -> 0.) Jan 19 '17 at 13:19
• Michael E2 Not exactly. In economics, one is obliged to assume that every upper level set of the consumer's ordering is convex, which is equivalent to the condition that any function that represents the consumer's ordering is quasiconcave (for definition see mjo.osborne.economics.utoronto.ca/index.php/tutorial/index/1/…). If the function is $C^2$ the condition of quasiconcavity is linked to the bordered hessian Jan 20 '17 at 6:01
• -> continued --- principal minors should be alternatively negative/ positive beginning with the second order --- by construction the first order is 0. If the function is strtictly quasi-convex then on has a maximum. Jan 20 '17 at 6:01
• @cyrille.piatecki It seems the same thing, no? At least the formula for bordered Hessian in the ref. link in your comment is the same. Jan 20 '17 at 10:34