0
$\begingroup$

I am trying to solve an equation which I believe cannot be done analytically, but can use a numerical approximation to get a result. The equation is: $$\frac{2*\sqrt{\pi}*h*s*e^{m^{2}/(2*s^2)}}{\sqrt{2}} = a$$ where $h, m,$ and $a$ are given constants. This is for a project that I'm writing in Java, and it would be infeasible to grab the solution output from another program such as Matlab, Mathematica, or some other scientific computing language for a couple reasons, one of which is that I will have to solve this equation hundreds of times with different values. Basically I am wondering if anybody knows of a library I can easily import and use for this kind of problem, and to possibly spell out how I would go about doing that. So far I have been looking through math libraries such as Apache Commons Math but cannot find out if they are appropriate. Thanks!

$\endgroup$
  • 1
    $\begingroup$ When a variable (here: m) appears in only one place it can usually be solved directly. And if you looked for s for example: That’s basic numerical mathematics, you don’t need a library for that. $\endgroup$ – gnasher729 Mar 17 at 7:53
0
$\begingroup$

You are asking how to solve $e^{ax^2}=b$ for $x$, given constants $a,b$. The solution is $x=\sqrt{\frac{1}{a} \log b}$, which can be computed (approximately) using standard algorithms for computing the log and the square root.

In particular, your specific equation has the solution

$$m = \sqrt{2s^2 \log (a/(\sqrt{2\pi} hs))}.$$

You can verify the correctness of this solution by plugging into the equation and verifying it works.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ I don't think it's that simple. I am fairly certain that you cannot find a symbolic solution for x with the equation I provided above. $\endgroup$ – JJJJJJJJJJJJJJJJ Mar 17 at 22:05
  • $\begingroup$ @JJJJJJJJJJJJJJJJ, I suggest you take another look. See my edited answer. Your certainty seems misplaced to me. $\endgroup$ – D.W. Mar 17 at 22:15
  • $\begingroup$ Sorry about that D.W., I meant to say m was a constant and s was the variable in question.. Did not mean to waste peoples' time. What I'm doing right now is Regula Falsi and it seems to be working alright. $\endgroup$ – JJJJJJJJJJJJJJJJ Mar 19 at 13:40
0
$\begingroup$

Quote: "I don't think it's that simple. I am fairly certain that you cannot find a symbolic solution for x with the equation I provided above. "

$$\frac{2*\sqrt{\pi}*h*s*e^{m^{2}/(2*s^2)}}{\sqrt{2}} = a$$

Multiply both sides by sqrt (2).

Divide both sides by 2 sqrt(pi) h s.

Take the natural logarithm.

Multiply by 2 s^2.

Take the square root.

Now m is alone on the left side, and the right side is the solution:

$$m = \sqrt {\ln (\frac {a \cdot \sqrt{2}}{2*\sqrt{\pi}*h*s}) \cdot (2\cdot s^2)}$$

(Of course it would help if you posted the problem you have, and not a different problem).

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ See my comment above - s is the variable in question. I already solved the problem anyway. $\endgroup$ – JJJJJJJJJJJJJJJJ Mar 22 at 3:46
  • $\begingroup$ I don't see why you feel the need to be a dick because I mistyped one variable. People make mistakes. $\endgroup$ – JJJJJJJJJJJJJJJJ Mar 23 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.