I have never used python but Mathematica can't handle the equation I am trying to solve. I am trying to solve for the variable "a" of the following equations where s, c, mu, and delta t are known parameters.
I tried doing NSolve, Solve, etc in Mathematica but it has been running for an hour with no luck. Since I am not familiar with Python, is there a way I can use Python to solve this equation for a?
You're not going to find an analytic solution to these equations because they're transcendental, containing a
both inside and outside of a trigonometric function.
I think the trouble you're having with numerical solutions is that the range of acceptable values for a
is constrained by the arcsin
. Since arcsin
is only defined for arguments between -1 and 1 (assuming you want a
to be real), your formulas for alpha
and beta
require that a > s/2
and a > (s-c)/2
.
In Python, you can find a zero of your third equation (rewritten in the form f(a) = 0
) using the brentq
function:
import numpy as np
from scipy.optimize import brentq
s = 10014.6
c = 6339.06
mu = 398600.0
dt = 780.0
def f(a):
alpha = 2*np.arcsin(np.sqrt(s/(2*a)))
beta = 2*np.arcsin(np.sqrt((s-c)/(2*a)))
return alpha - beta - (np.sin(alpha)-np.sin(beta)) - np.sqrt(mu/a**3)*dt
a0 = max(s/2, (s-c)/2)
a = brentq(f, a0, 10*a0)
Edit:
To clarify the way brentq(f,a,b)
works is that it searches for a zero of f
on an interval [a,b]
. Here, we know that a
is at least max(s/2, (s-c)/2)
. I just guessed that 10 times that was a plausible upper bound, and that worked for the given parameters. More generally, you need to make sure that f
changes sign between a
and b
. You can read more about how the function works in the SciPy docs.