0
$\begingroup$

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

Clear["Global`*"]

x[1] = CDF[NormalDistribution[\[Mu], \[Sigma]], c];
x[2] = Expectation[x^2 \[Conditioned] x > c, 
   x \[Distributed] NormalDistribution[\[Mu], \[Sigma]]];
x[3] = 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?

$\endgroup$
4
  • 5
    $\begingroup$ Use Coefficient[fun[\[Mu], \[Sigma], c, o], #] & /@ vars $\endgroup$
    – flinty
    Commented Jul 25, 2020 at 22:59
  • $\begingroup$ 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) $\endgroup$
    – Ararat
    Commented Jul 26, 2020 at 11:45
  • $\begingroup$ Please explain why the above doesn't work ? Just put: {oo, nn,mm} = ... at the front. $\endgroup$
    – flinty
    Commented Jul 26, 2020 at 11:50
  • $\begingroup$ 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... $\endgroup$
    – Ararat
    Commented Jul 26, 2020 at 13:20

1 Answer 1

0
$\begingroup$

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[3] -> xx[3] //. x[2] -> xx[2] //. x[1] -> xx[1];
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 *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.