Mathematica: Solve System of Eqs & Create Table

  • Context: Mathematica 
  • Thread starter Thread starter ilvreth
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
SUMMARY

This discussion focuses on solving a system of equations in Mathematica using the Reduce function and storing the solutions in a matrix format. The equations defined are eqs1, which includes trigonometric functions, and the optimization is constrained within specific ranges for the variables \[Phi] and \[Theta]. The solutions are obtained as pairs and can be stored in a matrix using the Solve function followed by a replacement operation. The final output is a matrix containing the pairs of solutions, demonstrating an efficient method to automate the process without manual copy-pasting.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of trigonometric equations and their solutions
  • Knowledge of matrix operations in Mathematica
  • Basic optimization techniques in mathematical programming
NEXT STEPS
  • Explore the Reduce function in Mathematica for complex equations
  • Learn about the Solve function and its applications in Mathematica
  • Investigate matrix manipulation techniques in Mathematica
  • Study optimization methods in Mathematica for constrained problems
USEFUL FOR

Mathematics students, researchers using Mathematica for solving equations, and anyone interested in automating data storage and manipulation in computational environments.

ilvreth
Messages
33
Reaction score
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
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}}
 
Oh, it was so easy finally..
Thank you!
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K