0

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.

  • This looks like a math question, rather than a question about the software Mathematica. – bbgodfrey May 05 '15 at 16:02
  • @bbgodfrey. No, the expression is the result of a Solve operation. It looks something like $\alpha \to \frac{1 + \sqrt{1 + 150 k^2}}{10 k}$. I need a way to get to that number 150 programmatically. – Steven Alexis Gregory May 05 '15 at 16:26
  • @bbgodfrey. OK. But it will take a while before I get home. – Steven Alexis Gregory May 05 '15 at 16:31
  • To be more precise, you must want something more challenging than just observing that the coefficient of k^2 is 150. As @Kuba noted, we need to understand just what are trying to accomplish in order to be of help. – bbgodfrey May 05 '15 at 16:35
  • No. All I want is to find the coefficient of $k^2$ and the solution will look more or less like my example. I could find the numerator, subtract 1, square it, subtract 1 again, and then divide by $k^2$; but this is Mathematica. There has to be a better way. – Steven Alexis Gregory May 05 '15 at 17:27
  • 1
    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 – LLlAMnYP May 05 '15 at 18:17
  • 1
    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. – Michael Seifert May 05 '15 at 18:23
  • 3
    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} – LLlAMnYP May 05 '15 at 18:24
  • @LLlAMnYP I didn't know I could do that. I hope it works too. – Steven Alexis Gregory May 05 '15 at 18:32
  • 1
    you can readily get the result analytically, a b (a+b)^2 times 4 if both odd. – george2079 May 06 '15 at 04:00
  • @george2079. If you mean $u v (u + v)^2$ etc., then I think you're right. I wasn't really sure that there were only two cases, but now I am. I'm not sure why, but I wanted to try and do this without using $u$ and $v$. – Steven Alexis Gregory May 06 '15 at 04:42
  • @MichaelSeifert Yes. That would be myNumber = If[EvenQ[u] || EvenQ[v], 1, 4] u v (u + v). I was just hoping I could do it with expression returned from Solve. – Steven Alexis Gregory May 06 '15 at 11:13

2 Answers2

3

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.

Michael Seifert
  • 15,208
  • 31
  • 68
1

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 )

george2079
  • 38,913
  • 1
  • 43
  • 110