Message Boards Message Boards

0
|
6418 Views
|
8 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Mathematica taking forever to solve a system of 3 non-linear equations.

Posted 4 years ago

The following code takes forever to run. It has 3 parameters and 3 equations. I don't understand what the problem is?

eq1 = ExpandAll[M^2 + L^2 - 2 M L cos [\[Phi]i] == a]
eq2 = ExpandAll[M^2 + X^2 - 2 M X cos [\[Phi]c] == b]
eq3 = ExpandAll[L^2 + X^2 - 2 L X cos [\[Phi]i - \[Phi]c] == c]

Solve[{eq1, eq2, eq3}, {L, M, X}, Reals]
POSTED BY: Neerav Kaushal
8 Replies
Posted 4 years ago

Neerav,

This works for me -- you have to remove the Reals because Solve can't know about your parameters without assumptions.

eq1 = ExpandAll[Mm^2 + Ll^2 - 2 Mm Ll Cos[\[Phi] i] == a]
eq2 = ExpandAll[Mm^2 + Xx^2 - 2 Mm Xx Cos[\[Phi] c] == b]
eq3 = ExpandAll[Ll^2 + Xx^2 - 2 Ll Xx Cos[\[Phi] i - \[Phi] c] == c]

Solve[{eq1, eq2, eq3}, {Ll, Mm, Xx}]
POSTED BY: Updating Name
Posted 4 years ago

Thanks for the update. In the argument for Cosine, i mean two angles, phii and phic. Its not the product of phi and c (because c is the RHS of eq. 3). So, I got the output but as I have very little knowledge of Mathematica, I have problem interpreting the result. I have attached the notebook.

{{Ll -> -((\[Sqrt](-8 a^2 b Cos[c \[Phi]]^4 + 
      OutputSizeLimit`Skeleton[377] + OutputSizeLimit`Skeleton[
      1] - \[Sqrt]((8 a^2 b Cos[c \[Phi]]^4 - 
           16 a b^2 Cos[c \[Phi]]^4 + OutputSizeLimit`Skeleton[
           373])^2 - 
         4 (OutputSizeLimit`Skeleton[195] + 
            16 a^2 c^2 OutputSizeLimit`Skeleton[
             1]^4 Cos[OutputSizeLimit`Skeleton[1]]^4) (16 b^2 Cos[
              c \[Phi]]^4 - 32 b c Cos[c \[Phi]]^4 + 
            16 c^2 Cos[c \[Phi]]^4 + OutputSizeLimit`Skeleton[
            282] + 16 a^2 Cos[c \[Phi] - i \[Phi]]^8 - 
            32 a b Cos[c \[Phi] - i \[Phi]]^8 + 
            16 b^2 Cos[c \[Phi] - i \[Phi]]^8))))/(Sqrt[
    2] \[Sqrt](16 b^2 Cos[c \[Phi]]^4 - 32 b c Cos[c \[Phi]]^4 + 
       16 c^2 Cos[c \[Phi]]^4 + 32 b c Cos[c \[Phi]]^6 - 
       32 c^2 Cos[c \[Phi]]^6 + OutputSizeLimit`Skeleton[276] + 
       32 a c Cos[c \[Phi]] Cos[i \[Phi]] Cos[
         c \[Phi] - i \[Phi]]^7 - 
       32 b c Cos[c \[Phi]] Cos[i \[Phi]] Cos[
         c \[Phi] - i \[Phi]]^7 + 
       16 a^2 Cos[c \[Phi] - i \[Phi]]^8 - 
       32 a b Cos[c \[Phi] - i \[Phi]]^8 + 
       16 b^2 Cos[c \[Phi] - i \[Phi]]^8))), 
  Mm -> OutputSizeLimit`Skeleton[1]/(
  OutputSizeLimit`Skeleton[1] + OutputSizeLimit`Skeleton[233] + 
OutputSizeLimit`Skeleton[1]), 
Xx -> OutputSizeLimit`Skeleton[1]/OutputSizeLimit`Skeleton[
1]}, {OutputSizeLimit`Skeleton[1]}, OutputSizeLimit`Skeleton[
1], {OutputSizeLimit`Skeleton[1]}}
Attachments:
POSTED BY: Neerav Kaushal
Posted 4 years ago

For any two of your three equations and two of your three variables

eq1 = M^2 + L^2 - 2 M L Cos[i] == a
eq2 = M^2 + X^2 - 2 M X Cos[cr] == b
eq3 = L^2 + X^2 - 2 L X Cos[i - cr] == c
Reduce[{eq2, eq3}, {L, M}]

it almost instantly returns a solution in terms of the remaining variables.

Is there any chance that you might more quickly be able to take the result of two of the two variable solutions and equate those find the overall solution and then verify your condition that the result be Real?

POSTED BY: Bill Nelson
Posted 4 years ago

When operating

Reduce[{eq2, eq3}, {L, M}]

I get the values of L and M in terms of X. Do you mean that I should put these values in eq1 to get the solution for X and then that value back in L and M? I tried this but still taking forever.

POSTED BY: Neerav Kaushal
Posted 4 years ago

I edited it as follows and it's again taking forever. Also, i is not iota.

eq1 = ExpandAll[M^2 + L^2 - 2 M L Cos[i] == a]
eq2 = ExpandAll[M^2 + X^2 - 2 M X Cos[cr] == b]
eq3 = ExpandAll[L^2 + X^2 - 2 L X Cos[i - cr] == c]
Solve[{eq1, eq2, eq3}, {L, M, X}, Reals]
POSTED BY: Neerav Kaushal
Posted 4 years ago

Hello Nareev,

"Phii" and "Phic" need spaces or "*": "Phi i" and "Phi c" OR "Phi*i" and "Phi*C" Also, "cos" needs to be "Cos" because Cosine is a built-in function of the Wolfram Language.

POSTED BY: Updating Name
Posted 4 years ago

Hi. Thanks for the reply. I tried what you said and now it's saying it can't be solved with the methods available to Solve

POSTED BY: Neerav Kaushal
Posted 4 years ago

Is i supposed to be the unit imaginary number? If so, it needs to be I. See this.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract