Home > Net >  Solving equations with square root, sin, and cos
Solving equations with square root, sin, and cos

Time:09-21

I am working on a project that involves equations with four different unknowns combined with square root, sin, and cos.

e.g.

 sqrt(2) (3/2)*sqrt(3) = a*cos(b)  c*cos(d)
-sqrt(2) (3/2)         = a*sin(b)  c*sin(d)
 13                    = a**2      c**2
  5                    = a         c

Possible answers (found by using GeoGebra):

[[a = 2, b = -45   , c = 3, d =  30   ], 
 [a = 2, b =  47.45, c = 3, d = -27.55], 
 [a = 3, b =  30   , c = 2, d = -45   ], 
 [a = 3, b = -27.55, c = 2, d =  47.45]]

NB: the variables b and d are angles in degrees (not radians)

I saw this post, Solving linear equation with four variables, where they solved it with NumPy, but that was with easier equations:

 a   3b   2c   2d = 1
2a    b    c   2d = 0
3a    b   2c    d = 1
2a         c   3d = 0

where the code was:

import numpy as np
A = np.array([[1,3,2,2],[2,1,1,2],[3,1,2,1],[2,0,1,3]])
B = np.array([1,0,1,0])
print(np.linalg.solve(A,B))

Output:

[-0.27272727 -0.18181818  1.09090909 -0.18181818]

I tried to use the same method, but I didn't seem to be able to convert my equations to a way this method could read.

CodePudding user response:

You could use sympy to solve the equations symbolically:

from sympy import S, Eq, sqrt, sin, cos, solve
from sympy.abc import a, b, c, d

equations = [Eq(sqrt(2)   (3 / S(2)) * sqrt(3), a * cos(b)   c * cos(d)),
             Eq(-sqrt(2)   (3 / S(2)), a * sin(b)   c * sin(d)),
             Eq(13, a ** 2   c ** 2),
             Eq(5, a   c)]
sol = solve(equations, [a, b, c, d])

Result:

[(2,
  -asin(-3/4   sqrt(2)/2   3*sin(2*atan((-2*sqrt(2)   3   2*sqrt(sqrt(3)   2))/(sqrt(2)   sqrt(6)   3*sqrt(3)   6)))/2),
  3,
  2*atan((-2*sqrt(2)   3   2*sqrt(sqrt(3)   2))/(sqrt(2)   sqrt(6)   3*sqrt(3)   6))),

 (2,
  asin(-sqrt(2)/2   3*sin(2*atan((-3   2*sqrt(2)   2*sqrt(sqrt(3)   2))/(sqrt(2)   sqrt(6)   3*sqrt(3)   6)))/2   3/4),
  3,
  -2*atan((-3   2*sqrt(2)   2*sqrt(sqrt(3)   2))/(sqrt(2)   sqrt(6)   3*sqrt(3)   6)))]

From here, evalf() obtains numerical solutions (in radians):

for sol_i in sol:
    print([x.evalf() for x in sol_i])
[2.00000000000000, -0.785398163397448, 3.00000000000000, 0.523598775598299]
[2.00000000000000, 0.828153484576581, 3.00000000000000, -0.480843454419166]
  • Related