# Finding roots of multivariable function

**URL:** <https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701>\
**Category:** Questions\
**Tags:** calculus, equation-solving\
**Created:** [March 9, 2024, 2:21pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701 "2024-03-09T14:21:21Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![15214400](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/15214400/32/21968_2.png) [@15214400](https://community.wolfram.com/u/15214400)\
**Post date:** [March 9, 2024, 2:21pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/1 "2024-03-09T14:21:21Z")

</div>

I have a real-valued function of four variables, namely L[\phi, m0, m1, m2]. I am interested in taking the partial derivative \partial\_{\phi}L thereof and setting the partial derivative to zero, that is \partial\_{\phi}L = 0. Then solving for \phi \in [0,2\pi] in terms of $m0, m1, m2 \in  
\mathbb{N}_{0}. I have reached the point in the attached code where I have generated the partial derivative \partial_{\phi}L$, but I am having difficulty setting the partial derivative to zero and getting an analytic expression for \phi in terms of the other variables m0,~m1 and m2. Please advise if there is a clear way of doing this analytically and numerically.

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/8a8e8c5b-b040-4954-bc13-f6fd943d5026)

Just a note that the function L[\phi, m0, m1, m2] is defined in terms of probabilities P1, P2 and P3, hence it has a real-valued output for any \phi \in \mathbb{R}. Link to [related Mathematica SE post](https://mathematica.stackexchange.com/questions/300241/solving-multivariable-equation-after-setting-partial-derivative-to-zero?noredirect=1#comment739470_300241).

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [March 9, 2024, 4:10pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/2 "2024-03-09T16:10:21Z")

</div>

The function L[ϕ,m0,m1,m2] is defined in terms of `P02,P11` and `P20`, not of P1,P2 and P3.

Assuming that `P02 = P1; P11 = P2; P20 = P3` you can do it this way:

```
Clear[\[Phi], m0, m1, m2, L, DL];
L[\[Phi]_, m0_, m1_, m2_] = 
  P1[\[Phi]]^m0*P2[\[Phi]]^m1*P3[\[Phi]]^m2;
DL[\[Phi]_, m0_, m1_, m2_] = 
  Simplify[D[L[\[Phi], m0, m1, m2], \[Phi]], Element[\[Phi], Reals]];
Reduce[DL[\[Phi], m0, m1, m2] == 0 &&
  Element[{m0, m1, m2}, PositiveIntegers] &&
  Element[\[Phi], Reals],
 \[Phi]]

```

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 9, 2024, 4:18pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/3 "2024-03-09T16:18:53Z")

</div>

Firstly, did you mean  
L(\phi, m\_0, m\_1, m\_2) = P\_{1}(\phi)^{m\_{0}} \cdot P\_2(\phi)^{m\_{1}} \cdot P\_3(\phi)^{m\_{2}}

'cause `P02, P11, P20` are not defined?

If so,we see that  
`FullSimplify@L[\[Phi], m0, m1, m2]`  
is  
2^{-\text{m0}-\text{m2}} \cos ^4\left(\frac{\phi }{2}\right)^{\text{m1}} \sin ^2(\phi )^{\text{m0}+\text{m2}}  
With this expression you could simply do any operations.

If we go further:  
`DL[\[Phi]_, m0_, m1_, m2_] :=FullSimplify@D[FullSimplify@L[\[Phi], m0, m1, m2], \[Phi]]`

2^{-\text{m0}-\text{m2}+1} \csc (\phi ) \cos ^4\left(\frac{\phi }{2}\right)^{\text{m1}} \sin ^2(\phi )^{\text{m0}+\text{m2}} (\cos (\phi ) (\text{m0}+\text{m1}+\text{m2})-\text{m1})

If we run (as in post Gianluca Gorni):  
`Reduce[DL[\[Phi], m0, m1, m2] == 0 && Element[{m0, m1, m2}, PositiveIntegers] && 0 <= \[Phi] <= 2 \[Pi], \[Phi]]`  
we get some (not very) complicated result, from which we could learn that `DL[\[Phi], m0, m1, m2] == 0 `  
iff:  
\phi=0,\pi,2 \pi or  
\phi=\arccos\left(\frac{\text{m1}}{\text{m0}+\text{m1}+\text{m2}}\right) or  
\phi=2 \pi -\arccos\left(\frac{\text{m1}}{\text{m0}+\text{m1}+\text{m2}}\right)

But if we try to substitute directly  
`DL[\[Phi], m0, m1, m2] /. \[Phi] -> {0, \[Pi], 2 \[Pi]}`  
we get  
`{ComplexInfinity, ComplexInfinity, ComplexInfinity}`  
We need more accurate testing:  
`Limit[DL[\[Phi], m0, m1, m2], \[Phi] -> #, Assumptions -> Element[{m0, m1, m2}, PositiveIntegers]] & /@ {0, \[Pi], 2 \[Pi]}`  
`{0, 0, 0}`  
so all five solutions are valid.

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 9, 2024, 4:53pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/4 "2024-03-09T16:53:05Z")

</div>

This is interesting example with some pitfalls.  
When i run your code directly, I get complex result with `Log` function.  
I suspect it is not so

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [March 9, 2024, 5:26pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/5 "2024-03-09T17:26:57Z")

</div>

The solutions are real, despite their appearance:

```
sol = Reduce[
  DL[\[Phi], m0, m1, m2] == 0 && 
   Element[{m0, m1, m2}, PositiveIntegers] && 
   Element[\[Phi], Reals], \[Phi]]; FullSimplify[ComplexExpand[sol], 
 m0 > 0 && m1 > 0 && m1 > 0]

```

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 9, 2024, 5:46pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/6 "2024-03-09T17:46:10Z")

</div>

Hmm, may be, but they have very simple trig form finally

---

<div class="post-metadata">

**Author:** ![15214400](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/15214400/32/21968_2.png) [@15214400](https://community.wolfram.com/u/15214400)\
**Post date:** [March 10, 2024, 2:16am UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/7 "2024-03-10T02:16:08Z")

</div>

Many thanks for your response. Firstly, yes P02 = P1; P11 = P2; P20 = P3. Why is it that you seem to get a different function when you FullSimplify at the start, they don’t seem to be equivalent. Please have a look at my adapted code using your what you suggest in your post:

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/79ee947c-350e-482a-8bcc-557af3bd8e58)

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 10, 2024, 4:45am UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/8 "2024-03-10T04:45:12Z")

</div>

Yes, you are wright, looks like I mess something (  
We can get firstly:  
`FullSimplify /@ {P1[\[Phi]] , P2[\[Phi]], P3[\[Phi]]}`  
\left\{\cos ^4\left(\frac{\phi }{2}\right),\frac{\sin ^2(\phi )}{2},\sin ^4\left(\frac{\phi }{2}\right)\right\}  
Cause \sin^2\left(\alpha/2\right)=\frac{1-\cos\left(\alpha\right)}{2}  
we can check result directly and your last post looks like fully correct!

---

<div class="post-metadata">

**Author:** ![15214400](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/15214400/32/21968_2.png) [@15214400](https://community.wolfram.com/u/15214400)\
**Post date:** [March 10, 2024, 5:48am UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/9 "2024-03-10T05:48:53Z")

</div>

Many thanks for your response. I attach the modified code where I attempt to explicitly show the 4th and 5th solutions (the solutions other than \phi = {0, \pi ,2\pi}). Do you agree with this code and the computation of the fourth and fifth roots:

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/fedd8e5d-a408-499d-b387-b8c1cced0ce1)

Lastly, at the end of your response you stated  
Limit[DL[[Phi], m0, m1, m2], [Phi] → #,  
Assumptions →   
Element[{m0, m1, m2}, PositiveIntegers]] & /@ {0, [Pi], 2 [Pi]}  
{0, 0, 0}  
so all five solutions are valid.

But it seems that you only tested the solutions \phi = 0, \pi ,2\pi yielding derivatives of {0, 0, 0}, yet you state ‘so all five solutions are valid’. Could you advise on this please.

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 10, 2024, 6:22am UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/10 "2024-03-10T06:22:44Z")

</div>

Yes, today later i’ll double check all calculations!

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [March 10, 2024, 10:18pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/11 "2024-03-10T22:18:13Z")

</div>

(1) This should link to the mathematica.stackexchange crosspost.

(2) The notebook should use consistent notation for `{P1,P2,P3}`.

(3) You might try the suggestion from a comment (mine) in MSE. Specifically, convert exponentials to trigs, and optimize the log of the expression of interest.

```
P1[\[Phi]_] := 
  2^-4*ExpToTrig[((E^(I*(\[Phi]/2)) + 
         E^(-I*(\[Phi]/2))) (E^(I*(-(\[Phi]/2))) + 
         E^(I*(\[Phi]/2))))]^2;
P2[\[Phi]_] := 
  2^-3 *ExpToTrig[(E^(I*(\[Phi])) - 
       E^(-I*(\[Phi]))) (E^(I*(-\[Phi])) - E^(I*(\[Phi])))];
P3[\[Phi]_] := 
  2^-4 *ExpToTrig[((E^(I*(\[Phi]/2)) - 
         E^(-I*(\[Phi]/2))) (E^(I*(-(\[Phi]/2))) - 
         E^(I*(\[Phi]/2))))]^2;
L[\[Phi]_, m0_, m1_, 
  m2_] := ((P1[\[Phi]])^m0)*((P2[\[Phi]])^m1)*((P3[\[Phi]])^m2)

In[24]:= llog = PowerExpand[Log[L[\[Phi], m0, m1, m2]]]

(* Out[24]= -m1 Log[2] + 4 m0 Log[Cos[\[Phi]/2]] + 
 4 m2 Log[Sin[\[Phi]/2]] + 2 m1 Log[Sin[\[Phi]]] *)

In[26]:= Solve[D[llog, \[Phi]] == 0, \[Phi]]

(* Out[26]= {{\[Phi] -> 
   ConditionalExpression[
    2 (-ArcTan[Sqrt[m1 + 2 m2]/Sqrt[
         2 m0 + m1]] + \[Pi] ConditionalExpression[
         1, \[Placeholder]]), 
    ConditionalExpression[1, \[Placeholder]] \[Element] 
     Integers]}, {\[Phi] -> 
   ConditionalExpression[
    2 (ArcTan[Sqrt[m1 + 2 m2]/Sqrt[
        2 m0 + m1]] + \[Pi] ConditionalExpression[1, \[Placeholder]]),
     ConditionalExpression[1, \[Placeholder]] \[Element] Integers]}} *)

```

---

<div class="post-metadata">

**Author:** ![ivanovdenis710616](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ivanovdenis710616/32/34915_2.png) [@ivanovdenis710616](https://community.wolfram.com/u/ivanovdenis710616)\
**Post date:** [March 11, 2024, 5:11am UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/12 "2024-03-11T05:11:52Z")

</div>

Idea with Log is very good, but don’t you miss roots \{0, \pi, 2\pi\} ?  
They are always there, as we could see from examples of Plot with different `m0,m1,m2`:

```
Manipulate[Plot[DL[\[Phi], m0, m1, m2], {\[Phi], 0, 2 \[Pi]}, 
  PlotRange -> Full], {{m0, 0.1}, 0.01, 10, 0.01}, {{m1, 0.1}, 0.0, 10, 0.01}, {{m2, 0.1}, 0.01, 10, 0.01}] 

```

 ![1.png](https://global.discourse-cdn.com/wolfram/original/3X/7/e/7edf5e57e073eea6fb2b3ffa824fb8ad3128f439.png)

 ![2.png](https://global.discourse-cdn.com/wolfram/original/2X/2/296f3a3f5a99c96a771fd1db32d099f0da104611.png)

 ![3.png](https://global.discourse-cdn.com/wolfram/original/3X/4/f/4f1ab935a2cb62052d8638a73a66cb8555a7b593.png)

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [March 11, 2024, 2:34pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/13 "2024-03-11T14:34:53Z")

</div>

Absolutely right, my method should also check for when the log is `-Infinity` (a boundary case, with this transformation). And, as you note, this happens at multiples of `Pi`. I should have caught that. Thanks for pointing out the missing solutions.

---

<div class="post-metadata">

**Author:** ![15214400](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/15214400/32/21968_2.png) [@15214400](https://community.wolfram.com/u/15214400)\
**Post date:** [March 12, 2024, 12:20pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/14 "2024-03-12T12:20:15Z")

</div>

One more query, is there a systematic way in Mathematica of identifying these indeterminate points from the log function itself. I don’t think Mathematica has built-in functions to find these indeterminate critical points?

---

<div class="post-metadata">

**Author:** ![15214400](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/15214400/32/21968_2.png) [@15214400](https://community.wolfram.com/u/15214400)\
**Post date:** [March 13, 2024, 12:50am UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/15 "2024-03-13T00:50:28Z")

</div>

Thanks.

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [March 13, 2024, 4:34pm UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/16 "2024-03-13T16:34:10Z")

</div>

Good question. I think one way is to find discontinuity points. Skipping some of the setup, here is hoq that could be done.

```
ee = -m1 Log[2] + 4 m0 Log[Cos[\[Phi]/2]] + 
   4 m2 Log[Sin[\[Phi]/2]] + 2 m1 Log[Sin[\[Phi]]];
Solve[FunctionDiscontinuities[{ee, 0 <= \[Phi] <= 2*Pi}, \[Phi]] && 
  0 <= \[Phi] <= 2*Pi, \[Phi]]

(* During evaluation of In[18]:= FunctionDiscontinuities::unkds: Warning: The set of discontinuities may be incomplete due to missing domain and discontinuity information for some of the functions involved.

Out[19]= {{\[Phi] -> 0}, {\[Phi] -> 
   0}, {\[Phi] -> \[Pi]}, {\[Phi] -> \[Pi]}, {\[Phi] -> 
   2 \[Pi]}, {\[Phi] -> 2 \[Pi]}} *)

```

---

<div class="post-metadata">

**Author:** ![15214400](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/15214400/32/21968_2.png) [@15214400](https://community.wolfram.com/u/15214400)\
**Post date:** [March 18, 2024, 11:52am UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/17 "2024-03-18T11:52:12Z")

</div>

Hi Daniel I am very interested in finding out why the different approaches in Mathematica yield different outcomes. If you have a chance could you please check out [this post](https://community.wolfram.com/groups/-/m/t/3142452?p_p_auth=1vZs4ENS) .

---

<div class="post-metadata">

**Author:** ![15214400](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/15214400/32/21968_2.png) [@15214400](https://community.wolfram.com/u/15214400)\
**Post date:** [April 2, 2024, 12:15am UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/18 "2024-04-02T00:15:18Z")

</div>

Hi, just a note for completeness of this post. I think there is a small problem in using PowerExpand to take the Log in this way. Consider that the Sine and Cosine functions take negative values hence you cannot use the Log property of taking the respective exponents of 4 and 2 and moving them to factors in front of the Log terms. If you take the Log of L[\phi, m1, m2, m3], I don’t think the log-function which you obtained is correct for this reason.  
Consider the attached code, where I use FullSimplify (as Ivanov noted):

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/037e88ba-409f-4fc3-a285-26aff0b1d25c)

---

<div class="post-metadata">

**Author:** ![danl](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danl/32/41267_2.png) [@danl](https://community.wolfram.com/u/danl)\
**Post date:** [April 2, 2024, 12:38am UTC](https://community.wolfram.com/t/finding-roots-of-multivariable-function/23701/19 "2024-04-02T00:38:58Z")

</div>

We take a derivative after that. Will the logs be off by something other than a constant in the variable `phi`?
