# How can I obtain the matrices of coefficients of quadratic form?

I'm trying to find the matrices of coefficients of a quadratic form:

Clear["Global*"]

x = CDF[NormalDistribution[\[Mu], \[Sigma]], c];
x = Expectation[x^2 \[Conditioned] x > c,
x \[Distributed] NormalDistribution[\[Mu], \[Sigma]]];
x = 1 - CDF[NormalDistribution[\[Mu], \[Sigma]], c];

m = Table[a[i, j], {i, 1, 3}, {j, 1, 3}]
n = Table[b[i], {i, 1, 3}]

vars = Table[x[i], {i, 1, 3}]
fun[\[Mu]_, \[Sigma]_, c_, o_] =vars.m.vars + n.vars + o


Suppose that all I observe is the expression for $$\text{fun}$$. I want to express it in matrix form in order to easily perform sums with other similar quadratic expressions. That is, I want to find $$\{\tilde{m}, \tilde{n},\tilde{o}\}$$ such that $$\text{fun(μ,σ,c,o)} ≡ \text{vars}^{\prime} \tilde{m} \text{vars} +\text{vars}^{\prime} \tilde{n} + \tilde{o}$$. My attempt using CoefficientArrays has not been successful:

{oo, nn,mm} =
Normal@CoefficientArrays[fun[\[Mu], \[Sigma], c, o], vars];


Any ideas on how to do that?

• Use Coefficient[fun[\[Mu], \[Sigma], c, o], #] & /@ vars Jul 25, 2020 at 22:59
• How do I use the coefficients obtained in this way to find $\{\tilde{m}, \tilde{n},\tilde{o}\}$ such that $\text{fun(μ,σ,c,o)} ≡ \text{vars}^{\prime} \tilde{m} \text{vars} +\text{vars}^{\prime} \tilde{n} + \tilde{o}$? I suppose the question wasn't clear enough, so I edited (my fault) Jul 26, 2020 at 11:45
• Please explain why the above doesn't work ? Just put: {oo, nn,mm} = ... at the front. Jul 26, 2020 at 11:50
• I was expecting one of those 3 terms to be equal to $o$, or that vars.mm.vars + nn.vars + oo == fun[\[Mu], \[Sigma], c, o] // Simplify would output "true". There is something that still escapes me... Jul 26, 2020 at 13:20

For some reason, those functions are not recognized as variables by CoefficientArrays. So, the following trick ended up by useful:

fun2[\[Mu]_, \[Sigma]_, c_,o_] = fun[\[Mu], \[Sigma], c,o]//. x -> xx //. x -> xx //. x -> xx;
vars2=Table[xx[i], {i, 1, 3}];
{oo, nn,mm} =
Normal@CoefficientArrays[fun2[\[Mu], \[Sigma], c,o],vars2];


Verifying it:

vars.mm.vars + nn.vars + oo == fun[\[Mu], \[Sigma], c,o] // Simplify
(* True *)
`