Mathematica: Solve System of Eqs & Create Table

  • Mathematica
  • Thread starter ilvreth
  • Start date
  • Tags
    Mathematica
In summary, the conversation discusses using Mathematica to solve a system of equations and store the resulting solutions as elements in a table. The solution is obtained through optimization with the Reduce function and can be stored using the Solve function. This allows for easy access to the solutions in a matrix format.
  • #1
ilvreth
33
0
Hi to all!

Again I have a question in mathematica.

Lets us define a system of equations e.q.

Code:
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:
Reduce[{eqs1 && 0 <= \[Phi] <= 2 \[Pi] && 
   0 <= \[Theta] <= \[Pi]}, {\[Phi], \[Theta]}, Reals]

The result we obtain for example is something like here

Code:
(\[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?
 
Physics news on Phys.org
  • #2
One possibility is
Code:
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:
A = {\[Phi], \[Theta]} /. sol
which results in
Code:
{{0.0882013, 1.55405}, {1.48259, 1.55405}, {3.22979, 
  1.55405}, {4.62419, 1.55405}}
 
  • #3
Oh, it was so easy finally..
Thank you!
 

1. How do I solve a system of equations in Mathematica?

To solve a system of equations in Mathematica, you can use the Solve function. This function takes in the equations as input and returns a list of solutions. For example, if you have the equations x + y = 5 and 2x - y = 1, you can use the command Solve[{x + y == 5, 2x - y == 1}, {x, y}] to solve for the values of x and y.

2. Can I solve a system of equations with inequalities in Mathematica?

Yes, you can use the Solve function to solve systems of equations with inequalities. You just need to include the inequalities in the list of equations, separated by commas. For example, to solve the system x + y < 5 and 2x - y > 1, you can use the command Solve[{x + y < 5, 2x - y > 1}, {x, y}].

3. How do I create a table of solutions in Mathematica?

To create a table of solutions in Mathematica, you can use the Table function. This function takes in an expression and a range of values as input and returns a table with the values of the expression for each value in the range. For example, if you have the solutions to the equations x = 1 and y = 2, you can use the command Table[{x, y}, {x, 1, 5}, {y, 2, 10}] to create a table with the values of x ranging from 1 to 5 and y ranging from 2 to 10.

4. Can I use the results from solving a system of equations in other calculations?

Yes, you can use the results from solving a system of equations in other calculations by assigning the solutions to variables. For example, if you solve the system x + y = 5 and 2x - y = 1 and want to use the value of x in another calculation, you can assign the solution to a variable xSol using the command xSol = Solve[{x + y == 5, 2x - y == 1}, {x, y}] and then use xSol[[1, 1, 2]] to access the value of x.

5. Is there a way to visualize the solutions to a system of equations in Mathematica?

Yes, there are various ways to visualize the solutions to a system of equations in Mathematica. One option is to use the ContourPlot function, which can plot the solutions to a system of equations as curves on a 2D graph. Another option is to use the VectorPlot function, which can plot the solutions as vectors on a 2D graph. You can also use the Plot3D function to plot the solutions in a 3D graph.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
221
  • Topology and Analysis
Replies
16
Views
521
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
562
Replies
3
Views
404
Back
Top