0
$\begingroup$

My goal is to solve $(\alpha - \dfrac{1}{\alpha}) - (\beta- \dfrac{1}{\beta}) = \dfrac 1 n$ where $\alpha$ and $\beta$ are rational and $n$ is a positive integer. Towards finding a particular solution, we will let $\beta = \dfrac{u}{v \alpha}$ where $u > v$ are positive integers.

myExpression[α_, β_]  := (α  - 1/α) - (β - 1/β)

myBase[u_, v_] := If[EvenQ[u] || EvenQ[v], (u v)/2, u v]

myQuad[u_, v_] := α /.
Solve[myExpression[α, u/(v α)] == 1/(myBase[u, v] k), α][[2]]

test = myQuad[3,2]

$\frac{1 + \sqrt{1 + 150 k^2}}{10 k}$

For $u = 3$ and $v = 2$ I get the expression shown above. What I need is to extract the 150 from the expression.

$\endgroup$
  • $\begingroup$ This looks like a math question, rather than a question about the software Mathematica. $\endgroup$ – bbgodfrey May 5 '15 at 16:02
  • 1
    $\begingroup$ If you know for a fact, that this will be the form of your expression, you can alway take a pattern-matching approach or taking the appropriate part. I'd start with putting the expression in TreeForm $\endgroup$ – LLlAMnYP May 5 '15 at 18:17
  • 1
    $\begingroup$ This looks like the root of a quadaratic equation of the form $\alpha k x^2 - x - \beta k = 0$, in which case the $n$ in your equation will always be $n = 4 \alpha \beta$. You might take a look at the equation you're solving and see if you can extract $\alpha$ and $\beta$ more easily at that step. $\endgroup$ – Michael Seifert May 5 '15 at 18:23
  • 3
    $\begingroup$ Try this, for example. Not sure, how robust it is, but should work for simple cases. (1 + Sqrt[1 - 150 k^2])/(m k) /. {(1 + Sqrt[1 + n_ k^2])/(m_ k) -> n} $\endgroup$ – LLlAMnYP May 5 '15 at 18:24
  • 1
    $\begingroup$ you can readily get the result analytically, a b (a+b)^2 times 4 if both odd. $\endgroup$ – george2079 May 6 '15 at 4:00
1
$\begingroup$

If you really want to parse the output you can do this (including a check for validity )

 Module[{m, n},
    {n, m} = {
       First@Cases[#  , Sqrt[1 + n_ k^2] :> n, {2}] , 
       1/#[[1]]} ;
    If[Simplify[(1 + Sqrt[1 + n k^2 ])/(m k) == #] , {n, m} ]] &@ myQuad[4, 3]

This only works because your function seems to always return exactly the same form (At least I couldn't find a case to break it )

$\endgroup$
  • $\begingroup$ I'm not going to be able to test this until this Sunday. But it looks promising. For a second, I thought it was written in APL. $\endgroup$ – Steven Gregory May 6 '15 at 20:05
3
$\begingroup$

Consider the function $f(k) = (1 + \sqrt{1 + n k^2})/m$ (note that this is your expression times $k$). We have $$ f(0) = \frac{2}{m} $$ $$ f''(0) = \frac{n}{m} $$ So the following Mathematica code does the trick:

(2 D[f, {k,2}] / f) /. k -> 0

In your case, you would need to define f = (your quantity)*k. Of course, this isn't really a solution by "parsing", but it does the trick.

$\endgroup$
  • $\begingroup$ You could also use f(k) = Numerator[$\alpha$] $\endgroup$ – Steven Gregory May 6 '15 at 11:02

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.