I have the function: $f(a_1, a_2) = a_1^2 \sigma_1^2 + a_2^2 \sigma_2^2$, which is subjected to the constraint: $a_1 + a_2 = 1$. I have obtained that: $$a_i = \frac{\sigma_i^{-2}}{\sum_{j = 1}^2 \sigma_j^{-2}},$$ optimizes $f$. I have two questions:

  1. Is there a possibility to verify that the above $a_i$ maximizes or minimizes the $f$ using Mathematica, in particular, by visualization?

  2. If the answer to the above question is yes, how the values of the function $f$ changes if we alter the exponents in $a_i$ from $-2$ to $-1$ or from $-2$ to $-3$?

  • 1
    $\begingroup$ Have you checked Minimize? For example Minimize[{a1^2 s1^2 + a2^2 s2^2 + a3^2 s3^2, a1 + a2 + a3 == 1}, {a1, a2, a3}, Reals] // FullSimplify $\endgroup$
    – Domen
    Sep 26 at 19:42
  • $\begingroup$ @Domen Thanks for your comment. I have tried that. In fact, I don't want to solve the optimization problem with Mathematica; I'm looking if there is any way of visualization with Mathematica in order to see if my obtained result, $a_i$, minimizes the function or not, then I would like to change the exponents in $a_i$ to see if the values of function increases or decreases. But I don't know how to do this. $\endgroup$
    – ARez
    Sep 26 at 19:49
  • $\begingroup$ @Domen I'm thinking that if I remove one of the variables and make the problem as: $f(a_1, a_2) = a_1^2 \sigma_1^2 + a_2^2 \sigma_2^2$, perhaps I could investigate the effects of changing the exponents in my formula for $a_i$ on the function $f$ by visualization. $\endgroup$
    – ARez
    Sep 26 at 20:23

Due to the constrain, you can write your function as a function of only 2 variables:

f[a1_,a2_]= a1^2 s1^2 + a2^2 s2^2 + (1 - a1 - a2)^2 s3^2;

To find all critical points (max., min or saddle) the following derivatives must be zero:

e1 = D[f[a1, a2], a1] == 0
e2 = D[f[a1, a2], a2] == 0
sol = Solve[{e1, e2}, {a1, a2}]

This results in:

and a3 we get by:

(1 - a1 - a2) /. sol // Simplify

Note that by dividing by s1^2s2^2s3^2 we get your solution.

To analyze what sort of critical point we have (max, min or saddle) we need the second derivatives (called "Hessian matrix"):

hes = D[f[a1, a2], {{a1, a2}, 2}]
(*{{2 s1^2 + 2 s3^2, 2 s3^2}, {2 s3^2, 2 s2^2 + 2 s3^2}}*)

We have an extremum if the determinant is >0:

(*4 s1^2 s2^2 + 4 s1^2 s3^2 + 4 s2^2 s3^2*)

This shows that we indeed have an extremum. We will have a minimum if both second derivatives are >0. That is


As both terms consist of squares we have a minimum.

  • $\begingroup$ Many thanks for writing an answer. I modified my question in order to become simpler. I have a question: Now, we know that $a_i = \frac{\sigma_i^{-2}}{\sum_{j = 1}^2 \sigma_j^{-2}}$ minimizes the function $f$. Is there any way, in particular visualization, to see how the values of $f$ changes if we alter the exponents in $a_i$. In other words, when one changes the exponents from $-1$ to $-3$, how $f$ reaches its minimum at $-2$. $\endgroup$
    – ARez
    Sep 26 at 20:46
  • $\begingroup$ Changing the question after getting an answer makes for confusion. Would be more clear if asked as a new question. $\endgroup$ Sep 26 at 22:25
  • $\begingroup$ @DanielLichtblau Sorry, I didn't know the culture here. Should I open a new question? $\endgroup$
    – ARez
    Sep 26 at 22:33
  • 1
    $\begingroup$ @ARez yes, you should open a new question as opposed to changing your original question (especially when it has been answered). $\endgroup$ Sep 26 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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