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
.