0
$\begingroup$

Suppose I have a function and its derivative like:

V = x^3.5 - x*y
Vx = D[V, x]

I first solve V for x, which depends on y, and then evaluate the derivative at this value:

z = x /. Solve[V == 0, x]
V2 = Vx /. x -> z

In this example z and V2 are both lists that depend on y, which remains a variable for now. Specifically, z will be a feedback rule that I want to substitute into a differential equation and solve.

I want to make a function (of y) that chooses the element of z that corresponds to the negative real element of V2, once a particular real value of y is plugged in.

How to do this is my question.

In this example, y > 0 results in Vy[[1]] < 0, in which case I want z[[1][ to be chosen. Alternatively, y < 0 results in Vy[[6]] < 0, in which case I want z[[6]] to be chosen.

A final point: the list for Vx in this example has clear real and imaginary numbers that can be identified BEFORE choosing a value of y. That is NOT the case in the more complex model I am actually dealing with: the real and imaginary elements of Vx change as y changes, so I cannot initially simplify the problem by simply focusing on the 1st and 6th elements. But I do know that my model always yields one negative root, so that a clear choice from z can be made for each y.

$\endgroup$
0

1 Answer 1

2
$\begingroup$

If you use rationals instead of floating point numbers, it seems easier:

V = x^(7/2) - x*y;
Vx = D[V, x];
z = x /. Solve[V == 0, x];
V2 = Vx /. x -> z
{-y, (5 y)/2}

It's now clear that the first is positive for y<0 and negative for y>0. To pick out your desired root, you can locate the smallest root at a desired value of y:

Min[V2 /. y -> 3]
-3
$\endgroup$
2
  • 1
    $\begingroup$ Thanks. This would work great if the problem I'm actually trying to solve were simpler. It didn't seem reasonable to print all my code here, but suffice it to say that I'm first solving a LOT of complicated expressions to get my V function (in my case V is the third derivative of a Hamilton-Jacobi equation), and the resulting list for V2 is defined by a series of Root[..] functions that would go on for many pages of expressions if I were to print up the solutions. I'm not sure I could figure out which parts of the expression could be re-expressed as rational numbers. $\endgroup$
    – Rick
    May 4, 2019 at 17:37
  • 1
    $\begingroup$ The point is you need to make all your numbers rational. So go back to your first equation, make sure everything is rational (especially exponents) and re-derive your expressions. If, as you claim, only one is negative, then that's going to be the minimum root. $\endgroup$
    – bill s
    May 4, 2019 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.