Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica:Solving two equations with two variables ?

  1. Jul 18, 2012 #1
    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 (Text):
    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.
     
  2. jcsd
  3. Jul 18, 2012 #2
    Re: Mathematica:Solving two equations with two variables ??

    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}
     
  4. Jul 18, 2012 #3

    phyzguy

    User Avatar
    Science Advisor

    Re: Mathematica:Solving two equations with two variables ??

    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 (Text):

    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}
     
     
  5. Jul 18, 2012 #4

    phyzguy

    User Avatar
    Science Advisor

    Re: Mathematica:Solving two equations with two variables ??

    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.
     
  6. Jul 18, 2012 #5
    Re: Mathematica:Solving two equations with two variables ??

    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 (Text):

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook