Mathematica:Solving two equations with two variables ?

  • Mathematica
  • Thread starter parazit
  • Start date
  • Tags
    Variables
In summary, the code finds the root of the system and then calculates the sf value for the given Ts[1,2] and Ts[3,4]
  • #1
parazit
75
3
Mathematica:Solving two equations with two variables ??

Hi,
I am trying to solve two equations with two unkonwn variables. These equations are equal to zero so my way was first picking one of the variable to one side of the equations and equalize them and find the other unknown parameter. After that, by using the known parameter, I can calculate the other one. Here is the codes from mathematica :

Code:
Ts[1,2] is :0.333184+sf (0.0559331+0.998885 Tan[\[Beta]ex])
Solution for sf with Ts[1,2]=0 = {{sf->-(0.333184/(0.0559331+0.998885 Tan[\[Beta]ex]))}}

Ts[3,4] is :13.0898+sf (1.00075-39.2433 Tan[\[Beta]ex-0.024 (1+Sin[\[Beta]ex]^2)])
Solution for sf with Ts[3,4]=0 = {{sf->-(13.0898/(1.00075-39.2433 Tan[\[Beta]ex-0.024 (1.+Sin[\[Beta]ex]^2)]))}}

In here, sf and [Beta]ex are unknowns. I decide to solve the equations for sf and then equalize them to find [Beta]ex. After getting [Beta]ex I could calculate sf.

However, I could not handle with that one. Please show me a way.

Thanks.
 
Physics news on Phys.org
  • #2


In[7]:= FindRoot[{0.333184+sf (0.0559331+0.998885 Tan[βex])==0,
13.0898+sf (1.00075-39.2433 Tan[βex-0.024 (1+Sin[βex]^2)])==0},{{sf, -4}, {βex, 10}}]

Out[7]= {sf->-6.32311,βex->9.42153}

In[8]:= {0.333184+sf (0.0559331+0.998885 Tan[βex]),
13.0898+sf (1.00075-39.2433 Tan[βex-0.024 (1+Sin[βex]^2)])}/.%

Out[8]= {2.9976021664879227`*^-15, -1.8118839761882555`*^-13}
 
  • #3


I usually use FindRoot to solve nonlinear systems like this one. It uses Newton's Method to converge on a solution given a starting point. It found the solution below, but there may be other solutions:

Code:
In[238]:= 
LHS = {0.333184 + sf (0.0559331 + 0.998885 Tan[\[Beta]ex]), 
   13.0898 + 
    sf (1.00075 - 
       39.2433 Tan[\[Beta]ex - 0.024 (1 + Sin[\[Beta]ex]^2)])};

In[252]:= Solution = 
 FindRoot[{0.333184 + sf (0.0559331 + 0.998885 Tan[\[Beta]ex]) == 0, 
   13.0898 + 
     sf (1.00075 - 
        39.2433 Tan[\[Beta]ex - 0.024 (1 + Sin[\[Beta]ex]^2)]) == 
    0}, {{sf, -6.0}, {\[Beta]ex, 0.20}}]

Out[252]= {sf -> -6.32311, \[Beta]ex -> -0.00324361}

In[253]:= LHS /. Solution

Out[253]= {1.27676*10^-15, -5.15143*10^-14}
 
  • #4


Note that Bill Simpson's solution and mine just have Betax differing by 3*pi. There will of course be an infinite number of solutions since Tan and Sin are periodic functions.
 
  • #5


Bill Simpson and phyzguy, thank you so much for quick answers. Here is my code and final result after some work. The result looks like a ok. I post the code so you can try it and discuss later.

Code:
Print["We'll use FindRoot command to find \
\[Beta]ex "]

rooot = FindRoot[-(0.33318362982304933`/(
     0.0559331001312733` + 0.998884522209502` Tan[\[Beta]ex])) + 
    13.08983820439489`/(
    1.0007491562059996` - 
     39.24333493677589` Tan[\[Beta]ex - 
        0.024` (1.` + Sin[\[Beta]ex]^2)]) == 0, {\[Beta]ex, 1.5}]

Print ["Calculated \[Beta]ex is assigned as rooot => \[Beta]ex = ", \
rooot]
myrooot = Evaluate[\[Beta]ex] /. rooot
Print ["Evaluated value is myrooot = ", myrooot]
Print["Calculated \[Beta]ex in degree is : ", myrooot  180/Pi // N]
Print ["Using \[Beta]ex value sf is calculated for Ts[1,2] as : ", tff]
tff = Evaluate[sf] /. tf ;
Print ["Numerical solution in meter for sf from Ts[1,2] is => sf= ", 
 tff /. \[Beta]ex -> myrooot]
Print ["Using \[Beta]ex value sf is calculated for Ts[3,4] as : ", tff]
ott = Evaluate[sf] /. ot ;
Print ["Numerical solution in meter for sf from Ts[3,4] is => sf= ", 
 ott /. \[Beta]ex -> myrooot]
sff = ott /. \[Beta]ex -> myrooot;
Print["Finally sf in meter=", sff]

Thank you again.
 

Related to Mathematica:Solving two equations with two variables ?

What is Mathematica?

Mathematica is a software program used for mathematical and scientific computations, visualization, and programming. It is commonly used by scientists, engineers, mathematicians, and researchers to solve complex mathematical problems.

How can Mathematica solve two equations with two variables?

Mathematica has built-in functions and algorithms that can solve systems of equations with two variables. By using the Solve or NSolve function, Mathematica can find the numerical or exact solutions to a set of equations with two variables.

What types of equations can Mathematica solve?

Mathematica can solve a variety of equations, including algebraic, differential, integral, and transcendental equations. It can also handle systems of equations, polynomial equations, and equations with complex numbers.

Can Mathematica handle equations with multiple solutions?

Yes, Mathematica can handle equations with multiple solutions. It can provide all possible solutions or a specific number of solutions, depending on the user's input. It can also handle cases where there are infinite solutions or no solutions.

Can Mathematica solve equations with constraints or parameters?

Yes, Mathematica has the capability to solve equations with constraints or parameters. By using the Reduce function, Mathematica can find solutions that satisfy a set of conditions or include specific parameters in the solution.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
29
Views
1K
  • Linear and Abstract Algebra
Replies
2
Views
1K
  • Advanced Physics Homework Help
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
6K
  • Precalculus Mathematics Homework Help
Replies
5
Views
1K
  • Precalculus Mathematics Homework Help
Replies
21
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
Back
Top