I have a Gaussian random variable $z$, whose mean $\mu$ and variance $\sigma^2$ are functions of two variables $x$ and $y$. Is there any way in MATLAB so that I can find the values of $x$ and $y$ for which $P(z)$ = $N(z$;$\mu$$(x,y)$,$\sigma$$(x,y))$ is maximised for a given value of $z$? Thanks in advance.

  • $\begingroup$ I don't understand your writing. Could you rephrase it? $\endgroup$
    – Royi
    Apr 12, 2016 at 5:01
  • $\begingroup$ I have rephrased the question. Please have a look. $\endgroup$ Apr 12, 2016 at 8:48
  • 1
    $\begingroup$ $P(z)$ is always maximum for $z=\mu$. You need to find $x,y$ such that $\mu(x,y)=z$. $\endgroup$
    – MBaz
    Apr 12, 2016 at 13:57
  • $\begingroup$ As @MBaz says, $P(z)$ will be maximized when $z = \mu(x,y),$ unless there are constraints on the values of $x$ and $y$ or on the function $\mu$ that mean $z = \mu(x,y)$ is impossible. Are there any other things about the problem that you're not telling us? $\endgroup$
    – Peter K.
    Apr 12, 2016 at 14:59

2 Answers 2


Try this:

[argvalue, argmin] = min(x);
[argvalue, argmax] = max(x);

Also, have a look to this question.


If you can express $\mu$ in an functional form, you could use fsolve.


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