I have an expected value:

$$ {\rm E}[\log(1+w_1x_1 + w_2x_2)] $$

where $w_1$, $w_2$ are constants and $x_1$, $x_2$ are two discrete variables. The discrete variables $x_1$ and $x_2$ take 2 possible values with a certain probability.

For example:

$$ x_1 = \begin{cases} a_1, \text{with probability }p_1 \\ b_1, \text{with probability }1 - p_1 \end{cases} $$

$$ x_2 = \begin{cases} a_2, \text{with probability }p_2 \\ b_2, \text{with probability }1 - p_2 \end{cases} $$

Assuming $x_1$ and $x_2$ are independent, my solution would be:

$$ log(1+w_1 a_1 +w_2 a_2) p_1p_2+ log(1+w_1 b_1 +w_2 a_2) (1-p_1)p_2+ log(1+w_1 b_1 +w_2 b_2) (1-p_1)(1-p_2)+ log(1+w_1 a_1 +w_2 b_2) p_1(1-p_2) $$

Now I want to

  1. generalise the "solution"
  2. write it in matrix form

How can I write this solution in matrix form the general case where we have more then 2 variables, each discrete (not binary but with many outcomes)?

  • $\begingroup$ Please don't post edited versions of your question in new threads: use the original thread. BTW, I suspect you are misunderstanding the meaning of "matrix" in a programming context: it's likely you are required to exploit Matlab's array-oriented functions. That differs from expressing the result in matrix notation (which is barely possible here but would be neither instructive nor practical). $\endgroup$
    – whuber
    Apr 15, 2022 at 16:06
  • $\begingroup$ This is a different question, as you also said on the other thread: “ That question is completely different from the one you have asked! Please see our help center for guidance on asking questions here. – whuber”. And you haven’t answer any of those questions . I still don’t know how to implement this with ‘array oriented functions’ without using for loops. $\endgroup$ Apr 15, 2022 at 19:01
  • $\begingroup$ That it's different doesn't matter, since nobody has yet attempted an answer. Unfortunately, your question is off topic here on CV. $\endgroup$
    – whuber
    Apr 15, 2022 at 19:09


Browse other questions tagged or ask your own question.