Mathematica:Solving two equations with two variables ?

  • Context: Mathematica 
  • Thread starter Thread starter parazit
  • Start date Start date
  • Tags Tags
    Variables
Click For Summary

Discussion Overview

The discussion revolves around solving a system of two nonlinear equations with two unknown variables, sf and [Beta]ex, using Mathematica. Participants share their approaches, code snippets, and results while exploring the implications of periodic functions in the solutions.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Exploratory

Main Points Raised

  • One participant describes their method of isolating one variable and substituting it into the other equation to find the unknowns.
  • Another participant suggests using the FindRoot function in Mathematica, providing specific code and initial guesses for the variables.
  • It is noted that FindRoot employs Newton's Method, which may converge to different solutions based on the starting point.
  • One participant points out that their solution differs from another's by a multiple of π, indicating the periodic nature of the trigonometric functions involved.
  • A participant shares their complete code and results, expressing satisfaction with the outcome and inviting further discussion on the approach taken.

Areas of Agreement / Disagreement

Participants express various methods and results without reaching a consensus on a single solution. The discussion highlights multiple potential solutions due to the periodicity of the functions involved.

Contextual Notes

The discussion includes assumptions about the initial values used in the FindRoot function and acknowledges the potential for multiple solutions due to the nature of the equations.

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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 29 ·
Replies
29
Views
4K
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 21 ·
Replies
21
Views
4K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K