# NMaximize with matrix input

I defined function f[x_, fixed_] := {...}. Here x is an $M\times N$ matrix. I want to maximize $f$ with respect to $x$. I have three questions:

1. By default, NMaximize treats all variables as real. How can I inform Mathematica that $x$ here is a real matrix?

2. I tried FindMaximum, by typing FindMaximum[f[x, fixed],{x}], with x as a matrix. The weird thing is that in the process of FindMaximum, my function f did not evaluate x; it just kept x as a variable name without content. How to understand and fix this thing? BTW, my function f is not in the global context but in a private context.

3. Indeed, the function $f$ here is an approximate of its theoretical counterpart $f_0$. And I know $f_0(x)$ is maximized when $x\in A$. Here $A$ is a subset in Euclid space. My actual aim is to approximate the set $A$. Let $x^*$ be the $\arg\max$ of $f$ found by Mathematica somehow. Intuitively, I want to keep all $x'$ such that $|f(x')-f(x^*)|<\epsilon$ for a chosen $\epsilon$. How can I achieve this goal? I noticed that NMaximize has a option called StepMonitor, which might help.

• A simple but brutal way is to use the explicit matrix elements as the arguments in FindMaximum. Something like FindMaximum[f[{{x11, x12}, {x21, x22}}, fixed],{x11, x12, x21, x22}]. – Silvia Jun 15 '13 at 10:14
• Look at the post Using FindMinimum with matrix input. It's on a similar topic. – ap21 Feb 12 '15 at 17:39