Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Choosing the smallest real part

  1. May 13, 2015 #1

    joshmccraney

    User Avatar
    Gold Member

    Hi PF!

    I am solving something in mathematica and I am finding three solutions, all of which are complex. I want to select the smallest real part. I know I could simply numerically check each, but is there a more systematic way to do this?

    Thanks!
     
  2. jcsd
  3. May 13, 2015 #2

    joshmccraney

    User Avatar
    Gold Member

    I should say, what I'm really wanting to do is operate over each of the outputs and take the smallest value.
     
  4. May 14, 2015 #3
    Assuming you have a (flattened) list of values:
    Code (Text):
    Min[Re[values]]
    Assuming you have a (flattened) list of rules:
    Code (Text):
    Min[Re[varname/.values[[#]]&/@Range@Length@values]]
    A (shorter) alternative would be:
    Code (Text):
    Min[Re[values[[All, 2]]]]
     
  5. May 16, 2015 #4

    joshmccraney

    User Avatar
    Gold Member

    Thanks so much for the help! Sadly this isn't working, or perhaps I just have no clue! My code is

    Code (Text):
    values = ComplexExpand[
      Roots[D[Integrate[(
            f''[x] f[x] + 2 (f'[x])^2 + x f'[x] - 2 a/(1 + a) f[x])^2, {x,
            0, 1}], A] == 0, A]]
    and when I use what you've said Mathematica is echoing out the responses. Am I applying this incorrectly?

    Thanks so much for taking the time to help me out!
     
  6. May 16, 2015 #5
    From what I can tell, you're trying to solve an equation of the kind [itex]\frac{\partial}{\partial a}\int_0^1(f''[x] f[x] + 2 (f'[x])^2 + x f'[x] - 2 a/(1 + a) f[x])^2=0[/itex] for a, correct? I believe this is a bit too much for Mathematica, unless you happen to know the exact form of [itex]f(x)[/itex]. I do have a couple of tips though:
    1. do NOT use Roots unless you're absolutely sure the end equation is a polynomial. This is because Roots works specifically on those, and it cannot solve equations such as [itex]x=\sin x[/itex] or something transcendental. Use NSolve, or, if you're lucky enough to know around which value the solutions are, use FindRoot instead. They both give you a (sometimes unflattened) list of replacement rules (things like {var->value1,var->value2,...}) on which you can use Flatten and my suggestion to find the smallest real part.
    2. do NOT use capital letters for variable/function names, anything user-made really. This is because all Mathematica expressions begin with a capital letter, and you may sometimes unintentionally try to use one as a variable, which will most likely result in errors.
    3. sometimes you have to make the first couple of steps in order to make the algebraic manipulation possible. In your case, I'm pretty sure you can expand the integrand, then put the derivative under the integral sign (since the lower and upper limits of integration are constants), and differentiate wrt to a. From there though, I'm pretty sure you need the explicit form of f(x) since the integration cannot be performed symbolically.
     
  7. May 16, 2015 #6

    joshmccraney

    User Avatar
    Gold Member

    Thanks a ton for the tips! I really appreciate it. And yes, ##f(x)## is a quadratic, with the leading coefficient to be determined. The entire code is then
    Code (Text):

    a = 0;(*CHECK THE a VALUE HERE*)
    f[x_] := A x^2 + B x + F
    F = -(A + B);
    B = -1/2 - 2 A;
    ComplexExpand[
    Roots[D[Integrate[(
           f''[x] f[x] + 2 (f'[x])^2 + x f'[x] - 2 a/(1 + a) f[x])^2, {x,
          0, 1}], A] == 0, A]]
     
    Although I'll probably change the variables from capital to lowercase. From here, I'm getting three solutions. Is there a technique you are aware of that can find the smallest real value from the three this code produces?
     
  8. May 17, 2015 #7
    Alright, now it's a bit clearer. On the last expression, you can use:
    Code (Text):
    Min@Part[Flatten@List@ToRules@(expr),All,2]
    Also, if you want an approximate numerical solution instead of an exact one, you can use NRoots instead of Roots, or just apply N to the entire expression. If you happen to be dealing with complex numbers, just replace Min@ by Min@Re@ for the smallest real part, and by Min@Im@ for the smallest complex part.

    Note: the "@"s are a shorthand notation for [ ], that is, "f@expr" is equivalent to "f[expr]" (it's used to avoid unnecessary brackets).
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Choosing the smallest real part
Loading...