Mathematica Mathematica:Solving two equations with two variables ?

  • Thread starter Thread starter parazit
  • Start date Start date
  • Tags Tags
    Variables
AI Thread Summary
The discussion focuses on solving two nonlinear equations with two unknowns, sf and [Beta]ex, using Mathematica's FindRoot function. The user initially attempted to isolate one variable and substitute it into the other equation but faced difficulties. After using FindRoot with specific starting values, a solution was obtained, showing that multiple solutions exist due to the periodic nature of the tangent and sine functions. The final results indicate the calculated values for sf and [Beta]ex, demonstrating the effectiveness of the method despite the complexity of the equations. The user shares their code and results for further discussion and verification.
parazit
Messages
75
Reaction score
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


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}
 


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}
 


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.
 


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.
 
Back
Top