0
$\begingroup$

I would like to use FindRoot for a problem of this type:

{f[x, y] == 0, g[x, y] == 0, 0 < y < x < 10}

My problem is that the interval is dependent on $ x, y $, so I don't know if it is possible to tell FindRoot to restrict its search. I tried including the inequality into the "equation" part as such :

FindRoot[{f[x, y] == 0, g[x, y] == 0, y < x}, {{x, 2, 0, 10}, {y, 1, 0, 10}}]

But of course this returns an error since FindRoot should take only equations.

Is there a way to do it or I have to program it myself from scratch?

To make myself clearer, I really need to find these solutions numerically, as there is no hope of finding them analytically. Here is the type of function I need to find the roots of, as per request:

f[m1_, m2_] := (2 l1)/(Sqrt[A] Sqrt[sp[m1, m2]]) ((EllipticK[sm[m1,m2]/sp[m1, m2]] (m1 - m2))/(m1 l1^2) + ((T^2 + Tc^2) - (m1 - m2)/(m1 l1^2)) EllipticPi[-((m1 l1^2)/sp[m1, m2]), sm[m1, m2]/sp[m1, m2]])

g[m1_,m2_] := (2 l2)/(Sqrt[A] Sqrt[sp[m1, m2]]) ((EllipticK[sm[m1, m2]/sp[m1, m2]] (m2 - m1))/(m2 l2^2) + ((T^2 - Tc^2) - (m2 - m1)/(m2 l2^2)) EllipticPi[-((m2 l2^2)/sp[m1, m2]), sm[m1, m2]/sp[m1, m2]])

Where l1, l2, A, sm[m1, m2], sp[x, y], T, Tc are numerical parameters/rational functions that are fixed. Not sure if this will be of much help.

Including the full definition of the functions is too long, I will try to produce a minimal working example that exhibits the same behavior as my functions.

$\endgroup$
8
  • $\begingroup$ Have you tried NSolve? $\endgroup$
    – MarcoB
    Dec 11 '20 at 16:56
  • $\begingroup$ I did, doesn't work for the type of functions I am using, which are defined Piecewise with transcendental functions... $\endgroup$
    – Frotaur
    Dec 11 '20 at 16:58
  • 1
    $\begingroup$ Please share a sample of your specific functions then, so we avoid wild guesses. $\endgroup$
    – MarcoB
    Dec 11 '20 at 17:00
  • 1
    $\begingroup$ Possible duplicate: mathematica.stackexchange.com/questions/10279/… -- For instance, how does FindMinimum[{f[x, y]^2 + g[x, y]^2, y < x}, {{x, 2, 0, 10}, {y, 1, 0, 10}}] work for you? You didn't include the full definitions, so I can't test & adjust. $\endgroup$
    – Michael E2
    Dec 11 '20 at 17:44
  • 2
    $\begingroup$ MWE: f[m1_, m2_] := m1^2 - 3 m1 m2 + m2^2 - 1; g[m1_, m2_] := m1^2 + m2^2 - 2; FindMinimum[{f[x, y]^2 + g[x, y]^2, y < x}, {{x, 1, 0, 10}, {y, 2, 0, 10}}] $\endgroup$
    – Michael E2
    Dec 11 '20 at 17:52
2
$\begingroup$

@Michael E2 has provide a good advice to do this. Here we review the other methods.

Since we doesn't know sp and other values in the original question,so here we only use the simple example take from the link in comment.

Clear[equations, conditions];
equations = {x y == z^3 - x, x y z == 2, x^2 + y^2 + z^3 == 5};
conditions = {-1 < x < 1, -3 < y < x - x^3, y < z < x};
terms = First /@ SubtractSides /@ equations

(* terms : {x + x y - z^3, -2 + x y z, -5 + x^2 + y^2 + z^3} *)

NMinimize[{0, terms^2 == 0, conditions}, {x, y, z}]
NMinimize[{0, Total[terms^2] == 0, conditions}, {x, y, z}]
NMinimize[{Total[terms^2], conditions}, {x, y, z}]
FindMinimum[{Total[terms^2], conditions}, {x, y, z}]

{0., {x -> 0.832027, y -> -2.32619, z -> -1.03335}}

{0., {x -> 0.832027, y -> -2.32619, z -> -1.03335}}

{8.74548*10^-18, {x -> 0.832027, y -> -2.32619, z -> -1.03335}}

{1.13829*10^-14, {x -> 0.832027, y -> -2.32619, z -> -1.03335}}

$\endgroup$

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