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 thearcsin
. Sincearcsin
is only defined for arguments between -1 and 1 (assuming you wanta
to be real), your formulas foralpha
andbeta
require thata > s/2
anda > (s-c)/2
.In Python, you can find a zero of your third equation (rewritten in the form
f(a) = 0
) using thebrentq
function:Edit:
To clarify the way
brentq(f,a,b)
works is that it searches for a zero off
on an interval[a,b]
. Here, we know thata
is at leastmax(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 thatf
changes sign betweena
andb
. You can read more about how the function works in the SciPy docs.I think its worth examining the behaviour of the function before atempting to solve it. Without doing that you dont know if there is a unique solution, many solutions, or no solution. (The biggest problem is many solutions, where numerical methods may not give you the solution you require/expect - and if you blindly use it "bad things" might happen). You examine the behaviour nicely using scipy and ipython. This is an example notebook that does that
This shows that we expect to find a solution with a between 8000 and 9000. The odd kink in the curve at about 5000 and earlier solution at about 4000 is due to the clipping required to make arcsin behave. Really the equation does not make sense below about a=5000. (exact value is the a0 given in Rays solution). This then gives a nice range that can be used with the techniques in Rays solution.