Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica: Tables

  1. May 31, 2013 #1
    Hi to all!

    Again I have a question in mathematica.

    Lets us define a system of equations e.q.

    Code (Text):
    eqs1 =-0.17544 Csc[\[Theta]]^2 + Sin[2 \[Phi]] == 0 &&
    0.001447 - 0.0864 Cos[\[Theta]] + 0.0288 Cos[\[Theta]]^3 == 0;
    and we want to find the solution by optimization with
    Code (Text):
    Reduce[{eqs1 && 0 <= \[Phi] <= 2 \[Pi] &&
       0 <= \[Theta] <= \[Pi]}, {\[Phi], \[Theta]}, Reals]
    The result we obtain for example is something like here

    Code (Text):
    (\[Phi] == 0.0882006 && \[Theta] == 1.55405) || (\[Phi] ==
        1.4826 && \[Theta] == 1.55405) || (\[Phi] ==
        3.22979 && \[Theta] == 1.55405) || (\[Phi] ==
        4.62419 && \[Theta] == 1.55405)
    We obtain 4 pairs of solutions.
    The question is, how we can store these pairs of solutions Phi and Theta into a table as elements so we can easily use them later for instance we want to store the pair solution

    \[Phi]=0.0882006 , \[Theta] = 1.55405
    as matrix elements like this A[1,1]=0.0882006, A[1,2]= 1.55405.

    How this can be done automatically without repeated copy-paste with the mouse for houres?
     
  2. jcsd
  3. May 31, 2013 #2

    DrClaude

    User Avatar

    Staff: Mentor

    One possibility is
    Code (Text):

    sol = Solve[(\[Phi] == 0.0882013 && \[Theta] == 1.55405) || (\[Phi] ==
          1.48259 && \[Theta] == 1.55405) || (\[Phi] ==
          3.22979 && \[Theta] == 1.55405) || (\[Phi] ==
          4.62419 && \[Theta] == 1.55405), {\[Theta], \[Phi]}]
     
    followed by
    Code (Text):
    A = {\[Phi], \[Theta]} /. sol
    which results in
    Code (Text):
    {{0.0882013, 1.55405}, {1.48259, 1.55405}, {3.22979,
      1.55405}, {4.62419, 1.55405}}
     
  4. May 31, 2013 #3
    Oh, it was so easy finally..
    Thank you!!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Mathematica: Tables
Loading...