# Choosing the smallest real part

• member 428835
In summary, in order to find the smallest real part from a list of complex solutions, you can use the expression "Min@Re@Part[Flatten@List@ToRules@(expr),All,2]". Additionally, if you want an approximate numerical solution, you can use NRoots or apply N to the entire expression. Just make sure to use lowercase variable names and avoid using Roots unless the equation is a polynomial.
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!

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.

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).

## What is the definition of "smallest real part"?

The smallest real part refers to the smallest numerical value in a set of real numbers. It can also refer to the smallest magnitude or absolute value in a set of complex numbers.

## Why is choosing the smallest real part important in scientific research?

In many scientific fields, the smallest real part is used as a measure of accuracy or precision. It can also be used to identify outliers or anomalies in data sets.

## How do I determine the smallest real part in a set of numbers?

To determine the smallest real part, you can arrange the numbers in ascending order and then select the first number in the list. Alternatively, you can use mathematical functions or algorithms to find the smallest real part.

## Can the smallest real part ever be negative?

Yes, the smallest real part can be negative if the set of numbers includes negative values. In this case, the smallest real part would be the number with the smallest negative value.

## Are there any limitations to using the smallest real part in scientific analysis?

While the smallest real part can provide valuable information, it should not be the only factor considered in scientific analysis. It is important to also consider other numerical values and factors that may affect the data set.

• MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
• Linear and Abstract Algebra
Replies
2
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
• Engineering and Comp Sci Homework Help
Replies
17
Views
414
Replies
6
Views
437
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K