System of equation with Mathematica: HELP

In summary, the conversation discusses solving a system of equations using Mathematica and finding solutions with a numerical method or MATLAB. The code for solving the equations is provided and a slight improvement is made. The conversation ends with a thank you and a question about rewriting the code in MATLAB.
  • #1
ilvreth
33
0
System of equations with Mathematica: HELP

Hi there. I am trying to solve a system of equations. I have written a mathematica code to solve this systems
Code:
<< VectorAnalysis`
Kc > Ku > 0;
Kuz > 0;
SS = 2.5;
Hfz > 0;
Kc = 0.0144;
Ku = Kc/3;
Kuz = 5 Kc;
B = 0.1;
Hfz = 0.1157676*B;
S = {Sx, Sy, Sz};
Eh = Kc (Sx^2  Sy^2 + Sx^2  Sz^2 + Sy^2   Sz^2) + Kuz   Sz^2 - Ku  Sx  Sy + SS  Hfz Sz; 
Heffx = D[Eh, Sx];
Heffy = D[Eh, Sy];
Heffz = D[Eh, Sz];
Heff = -{Heffx, Heffy, Heffz};
Cross[S, Heff]; 
Sx = Sin[\[Phi]] Sin[\[Theta]];
Sy = Cos[\[Phi]] Sin[\[Theta]];
Sz = Cos[\[Theta]]; 
eq = Cross[S, Heff] == 0;
Reduce[{eq && 0 <= \[Phi] <= 2 \[Pi] && 0 <= \[Theta] <= \[Pi]}, {\[Phi], \[Theta]}, Reals]

where B is the magnetic field in Tesla. When i have B=0 it finds solution (which is simple without mathematica). But when you put a magnetic field e.g. B=0.1 does not give a solution and the program is running anyway...

Is there any way to find solutions with a numerical method or something?
(The system of equations contains 3 equations and these are the 3 components of the vector S x Heff )
 
Last edited:
Physics news on Phys.org
  • #2
I managed to make a slight improvement.
I'll just give you the code

Code:
eq = Cross[S, Heff] == {0, 0, 0} // Thread // FullSimplify
criteria[\[Phi]_, \[Theta]_] := \[Phi] \[Element] 
   Reals && \[Theta] \[Element] Reals && 0 <= \[Phi] <= 2 \[Pi] && 
  0 <= \[Theta] < \[Pi]
Select[NSolve[eq, {\[Theta], \[Phi]}], 
 criteria[\[Phi] /. #, \[Theta] /. #] &]
If you get confused, just shout, ok?
 
  • #3
Thank you very much my friend! Thank you for you help!
 
  • #4
How this code could be written in MATLAB?
 
  • #5


Hi there. It looks like you have a very interesting system of equations to solve. Mathematica is a powerful tool for solving complex systems of equations, but it does require a solid understanding of the syntax and functions used. In order to help you with your specific problem, I would need more information about your equations and what you are trying to solve for. However, I can offer some general advice for using Mathematica to solve systems of equations.

First, make sure that your equations are written correctly using the proper syntax and functions. Double check your code to ensure that there are no typos or missing parentheses.

Next, you can try using the "NSolve" function, which is specifically designed for solving numerical equations. You can also try using the "FindRoot" function, which can find numerical solutions to equations by starting with a initial guess.

It is also important to check that your equations are solvable given the values you are inputting. For example, if your equations have complex solutions, you may need to specify that you are looking for real solutions using the "Reals" option.

I would also recommend checking the Mathematica documentation or seeking help from other Mathematica users on online forums or communities. They may have more specific knowledge about your equations and how to solve them using Mathematica.

I hope this helps and good luck with your research!
 

Related to System of equation with Mathematica: HELP

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

To solve a system of equations in Mathematica, you can use the command Solve[{equation1, equation2, ...}, {variable1, variable2, ...}]. This will return a list of solutions for the specified variables.

2. Can I plot the solutions to a system of equations in Mathematica?

Yes, you can use the command ContourPlot to plot the solutions to a system of equations. This will create a graphical representation of the intersection points of the equations.

3. How do I input equations in Mathematica?

You can input equations in Mathematica using the == operator. For example, to input the equation y = 2x + 3, you would type y == 2x + 3 into the command line.

4. Can I solve a system of equations symbolically in Mathematica?

Yes, you can use the command Solve with the option Assumptions to solve a system of equations symbolically. This will allow you to specify any assumptions or constraints for the variables in the equations.

5. How do I check the consistency of a system of equations in Mathematica?

To check the consistency of a system of equations in Mathematica, you can use the Reduce function. If the system is consistent, Reduce will return True and if it is inconsistent, it will return False.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • Advanced Physics Homework Help
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Replies
2
Views
1K
  • Advanced Physics Homework Help
Replies
10
Views
2K
Back
Top