Choosing the smallest real part

  • Thread starter Thread starter member 428835
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around selecting the smallest real part from a set of complex solutions generated by Mathematica. Participants explore methods for systematically identifying this value, particularly in the context of solving a specific mathematical equation involving derivatives and integrals.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant seeks a systematic method to select the smallest real part from complex solutions in Mathematica.
  • Another participant suggests using the function Min[Re[values]] for a flattened list of values to find the smallest real part.
  • Multiple participants provide variations of the Min function to handle different data structures, such as lists of rules.
  • Concerns are raised about the appropriateness of using the Roots function, with suggestions to use NSolve or FindRoot instead, particularly if the equation is not polynomial.
  • Participants discuss the importance of using lowercase letters for variable names in Mathematica to avoid conflicts with built-in functions.
  • One participant clarifies that their function f(x) is quadratic and shares their code, seeking further advice on finding the smallest real value from the solutions produced.
  • A later reply introduces the use of NRoots for approximate numerical solutions and discusses handling complex numbers in the context of finding minimum values.

Areas of Agreement / Disagreement

Participants express varying opinions on the best methods to use in Mathematica, particularly regarding the use of Roots versus other functions. The discussion includes multiple approaches without a clear consensus on the optimal solution.

Contextual Notes

Some participants note the potential limitations of Mathematica in solving certain types of equations, particularly those that are not polynomial. There is also mention of the need for an explicit form of f(x) for symbolic integration.

Who May Find This Useful

This discussion may be useful for Mathematica users dealing with complex solutions, particularly in mathematical modeling or research contexts where selecting specific solution characteristics is necessary.

member 428835
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!
 
Physics news on Phys.org
I should say, what I'm really wanting to do is operate over each of the outputs and take the smallest value.
 
Assuming you have a (flattened) list of values:
Code:
Min[Re[values]]
Assuming you have a (flattened) list of rules:
Code:
Min[Re[varname/.values[[#]]&/@Range@Length@values]]
A (shorter) alternative would be:
Code:
Min[Re[values[[All, 2]]]]
 
kontejnjer said:
Assuming you have a (flattened) list of values:
Code:
Min[Re[values]]
Assuming you have a (flattened) list of rules:
Code:
Min[Re[varname/.values[[#]]&/@Range@Length@values]]
A (shorter) alternative would be:
Code:
Min[Re[values[[All, 2]]]]
Thanks so much for the help! Sadly this isn't working, or perhaps I just have no clue! My code is

Code:
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!
 
From what I can tell, you're trying to solve an equation of the kind \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 for a, correct? I believe this is a bit too much for Mathematica, unless you happen to know the exact form of f(x). 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 x=\sin x 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.
 
  • Like
Likes   Reactions: member 428835
kontejnjer said:
From what I can tell, you're trying to solve an equation of the kind \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 for a, correct? I believe this is a bit too much for Mathematica, unless you happen to know the exact form of f(x). I do have a couple of tips though:
1. do NOT use Roots unless you're absolutely sure the end equation is a polynomial.
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:
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?
 
Alright, now it's a bit clearer. On the last expression, you can use:
Code:
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).
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K