NMaximize is not converging to a solutionDeclaration of variables in large Linear Programming model with NMaximizeHow trustworthy is NMaximize?Numeric range: present or notMaximalBy[#, “votes”] & not equal to MaximalBy[“votes”]?Maximimize not working properly?Does fitting data get stuck by non-homogeneous interval of data?How to find maximum (not with numbers,but with parameters) of 2-variables function under constraints?Hot to single out numeric values from NMaximizeNSum: Summand (or its derivative) is not numerical at pointProblem with constraints of NMaximize

Why can't I see bouncing of a switch on an oscilloscope?

Can a Cauchy sequence converge for one metric while not converging for another?

Add text to same line using sed

Is it possible to run Internet Explorer on OS X El Capitan?

Can a vampire attack twice with their claws using Multiattack?

How do I deal with an unproductive colleague in a small company?

Are the number of citations and number of published articles the most important criteria for a tenure promotion?

How does quantile regression compare to logistic regression with the variable split at the quantile?

Was any UN Security Council vote triple-vetoed?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

How does one intimidate enemies without having the capacity for violence?

What would happen to a modern skyscraper if it rains micro blackholes?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

High voltage LED indicator 40-1000 VDC without additional power supply

tikz convert color string to hex value

What defenses are there against being summoned by the Gate spell?

A case of the sniffles

Why do I get two different answers for this counting problem?

How can bays and straits be determined in a procedurally generated map?

Malformed Address '10.10.21.08/24', must be X.X.X.X/NN or

What typically incentivizes a professor to change jobs to a lower ranking university?

Do I have a twin with permutated remainders?

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

dbcc cleantable batch size explanation



NMaximize is not converging to a solution


Declaration of variables in large Linear Programming model with NMaximizeHow trustworthy is NMaximize?Numeric range: present or notMaximalBy[#, “votes”] & not equal to MaximalBy[“votes”]?Maximimize not working properly?Does fitting data get stuck by non-homogeneous interval of data?How to find maximum (not with numbers,but with parameters) of 2-variables function under constraints?Hot to single out numeric values from NMaximizeNSum: Summand (or its derivative) is not numerical at pointProblem with constraints of NMaximize













2












$begingroup$


I am trying to use NMaximize to find the maximum value of a variable that satisfies the given constraints. Since the constraints aren't straightforward, I am using the function.



I can see the constraints are such that the value is bounded but I get the below warning messages:




NMaximize::cvmit: Failed to converge to the requested accuracy or
precision within 100000 iterations.



NMaximize::cvdiv: Failed to
converge to a solution. The function may be unbounded.




The constraint and the way I am using the function is as below:



 constraint = (x | y) [Element] 
Integers && ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. &&
0 <= y <
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x -
3.63201*10^84 x^2]) || (10713. <= x <= 19762. &&
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x - 3.63201*10^84 x^2] < y <
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x - 3.63201*10^84 x^2]))


maxX =
NMaximize[x, constraint, x, y, MaxIterations -> 100000]


I have increased the MaxIterations from 100 to 100000 but it doesn't seem to converge. I am not sure if increasing the MaxIterations is the solution. Can you please guide me with this?










share|improve this question









$endgroup$











  • $begingroup$
    Could try maximizing over individual regions of the piecewise set-up. But the machine precision values will make validation of inequalities kind of iffy.
    $endgroup$
    – Daniel Lichtblau
    9 hours ago






  • 1




    $begingroup$
    I'm not seeing what $y$ has to do with this. Wouldn't the maximum value of $x$ be 19762? constraint /. x -> 19762 results in y [Element] Integers && 7229.16 < y < 7344.29 and constraint /. x -> 19763 results in False.
    $endgroup$
    – JimB
    9 hours ago











  • $begingroup$
    @JimB, I think for x, y isn't needed. Thanks for pointing this out. But if I am trying to maximize y, I need to maximize over both the variables since y is an expression of x, right?
    $endgroup$
    – gaganso
    9 hours ago










  • $begingroup$
    Yes, if that's what you want. The general solution appears to be $x = 19762$ and $7230leq y leq 7344$. So to maximize $y$ you'd choose $7344$.
    $endgroup$
    – JimB
    8 hours ago











  • $begingroup$
    @JimB, thank you. But I think the value of $y$ can be greater than 7344 for different values of $x$. For example, at $x = 7504$, the maximum value of y is 13937.
    $endgroup$
    – gaganso
    8 hours ago















2












$begingroup$


I am trying to use NMaximize to find the maximum value of a variable that satisfies the given constraints. Since the constraints aren't straightforward, I am using the function.



I can see the constraints are such that the value is bounded but I get the below warning messages:




NMaximize::cvmit: Failed to converge to the requested accuracy or
precision within 100000 iterations.



NMaximize::cvdiv: Failed to
converge to a solution. The function may be unbounded.




The constraint and the way I am using the function is as below:



 constraint = (x | y) [Element] 
Integers && ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. &&
0 <= y <
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x -
3.63201*10^84 x^2]) || (10713. <= x <= 19762. &&
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x - 3.63201*10^84 x^2] < y <
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x - 3.63201*10^84 x^2]))


maxX =
NMaximize[x, constraint, x, y, MaxIterations -> 100000]


I have increased the MaxIterations from 100 to 100000 but it doesn't seem to converge. I am not sure if increasing the MaxIterations is the solution. Can you please guide me with this?










share|improve this question









$endgroup$











  • $begingroup$
    Could try maximizing over individual regions of the piecewise set-up. But the machine precision values will make validation of inequalities kind of iffy.
    $endgroup$
    – Daniel Lichtblau
    9 hours ago






  • 1




    $begingroup$
    I'm not seeing what $y$ has to do with this. Wouldn't the maximum value of $x$ be 19762? constraint /. x -> 19762 results in y [Element] Integers && 7229.16 < y < 7344.29 and constraint /. x -> 19763 results in False.
    $endgroup$
    – JimB
    9 hours ago











  • $begingroup$
    @JimB, I think for x, y isn't needed. Thanks for pointing this out. But if I am trying to maximize y, I need to maximize over both the variables since y is an expression of x, right?
    $endgroup$
    – gaganso
    9 hours ago










  • $begingroup$
    Yes, if that's what you want. The general solution appears to be $x = 19762$ and $7230leq y leq 7344$. So to maximize $y$ you'd choose $7344$.
    $endgroup$
    – JimB
    8 hours ago











  • $begingroup$
    @JimB, thank you. But I think the value of $y$ can be greater than 7344 for different values of $x$. For example, at $x = 7504$, the maximum value of y is 13937.
    $endgroup$
    – gaganso
    8 hours ago













2












2








2





$begingroup$


I am trying to use NMaximize to find the maximum value of a variable that satisfies the given constraints. Since the constraints aren't straightforward, I am using the function.



I can see the constraints are such that the value is bounded but I get the below warning messages:




NMaximize::cvmit: Failed to converge to the requested accuracy or
precision within 100000 iterations.



NMaximize::cvdiv: Failed to
converge to a solution. The function may be unbounded.




The constraint and the way I am using the function is as below:



 constraint = (x | y) [Element] 
Integers && ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. &&
0 <= y <
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x -
3.63201*10^84 x^2]) || (10713. <= x <= 19762. &&
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x - 3.63201*10^84 x^2] < y <
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x - 3.63201*10^84 x^2]))


maxX =
NMaximize[x, constraint, x, y, MaxIterations -> 100000]


I have increased the MaxIterations from 100 to 100000 but it doesn't seem to converge. I am not sure if increasing the MaxIterations is the solution. Can you please guide me with this?










share|improve this question









$endgroup$




I am trying to use NMaximize to find the maximum value of a variable that satisfies the given constraints. Since the constraints aren't straightforward, I am using the function.



I can see the constraints are such that the value is bounded but I get the below warning messages:




NMaximize::cvmit: Failed to converge to the requested accuracy or
precision within 100000 iterations.



NMaximize::cvdiv: Failed to
converge to a solution. The function may be unbounded.




The constraint and the way I am using the function is as below:



 constraint = (x | y) [Element] 
Integers && ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. &&
0 <= y <
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x -
3.63201*10^84 x^2]) || (10713. <= x <= 19762. &&
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x - 3.63201*10^84 x^2] < y <
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-43 Sqrt[
4.98614*10^92 + 4.65469*10^88 x - 3.63201*10^84 x^2]))


maxX =
NMaximize[x, constraint, x, y, MaxIterations -> 100000]


I have increased the MaxIterations from 100 to 100000 but it doesn't seem to converge. I am not sure if increasing the MaxIterations is the solution. Can you please guide me with this?







functions maximum






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 10 hours ago









gagansogaganso

1477




1477











  • $begingroup$
    Could try maximizing over individual regions of the piecewise set-up. But the machine precision values will make validation of inequalities kind of iffy.
    $endgroup$
    – Daniel Lichtblau
    9 hours ago






  • 1




    $begingroup$
    I'm not seeing what $y$ has to do with this. Wouldn't the maximum value of $x$ be 19762? constraint /. x -> 19762 results in y [Element] Integers && 7229.16 < y < 7344.29 and constraint /. x -> 19763 results in False.
    $endgroup$
    – JimB
    9 hours ago











  • $begingroup$
    @JimB, I think for x, y isn't needed. Thanks for pointing this out. But if I am trying to maximize y, I need to maximize over both the variables since y is an expression of x, right?
    $endgroup$
    – gaganso
    9 hours ago










  • $begingroup$
    Yes, if that's what you want. The general solution appears to be $x = 19762$ and $7230leq y leq 7344$. So to maximize $y$ you'd choose $7344$.
    $endgroup$
    – JimB
    8 hours ago











  • $begingroup$
    @JimB, thank you. But I think the value of $y$ can be greater than 7344 for different values of $x$. For example, at $x = 7504$, the maximum value of y is 13937.
    $endgroup$
    – gaganso
    8 hours ago
















  • $begingroup$
    Could try maximizing over individual regions of the piecewise set-up. But the machine precision values will make validation of inequalities kind of iffy.
    $endgroup$
    – Daniel Lichtblau
    9 hours ago






  • 1




    $begingroup$
    I'm not seeing what $y$ has to do with this. Wouldn't the maximum value of $x$ be 19762? constraint /. x -> 19762 results in y [Element] Integers && 7229.16 < y < 7344.29 and constraint /. x -> 19763 results in False.
    $endgroup$
    – JimB
    9 hours ago











  • $begingroup$
    @JimB, I think for x, y isn't needed. Thanks for pointing this out. But if I am trying to maximize y, I need to maximize over both the variables since y is an expression of x, right?
    $endgroup$
    – gaganso
    9 hours ago










  • $begingroup$
    Yes, if that's what you want. The general solution appears to be $x = 19762$ and $7230leq y leq 7344$. So to maximize $y$ you'd choose $7344$.
    $endgroup$
    – JimB
    8 hours ago











  • $begingroup$
    @JimB, thank you. But I think the value of $y$ can be greater than 7344 for different values of $x$. For example, at $x = 7504$, the maximum value of y is 13937.
    $endgroup$
    – gaganso
    8 hours ago















$begingroup$
Could try maximizing over individual regions of the piecewise set-up. But the machine precision values will make validation of inequalities kind of iffy.
$endgroup$
– Daniel Lichtblau
9 hours ago




$begingroup$
Could try maximizing over individual regions of the piecewise set-up. But the machine precision values will make validation of inequalities kind of iffy.
$endgroup$
– Daniel Lichtblau
9 hours ago




1




1




$begingroup$
I'm not seeing what $y$ has to do with this. Wouldn't the maximum value of $x$ be 19762? constraint /. x -> 19762 results in y [Element] Integers && 7229.16 < y < 7344.29 and constraint /. x -> 19763 results in False.
$endgroup$
– JimB
9 hours ago





$begingroup$
I'm not seeing what $y$ has to do with this. Wouldn't the maximum value of $x$ be 19762? constraint /. x -> 19762 results in y [Element] Integers && 7229.16 < y < 7344.29 and constraint /. x -> 19763 results in False.
$endgroup$
– JimB
9 hours ago













$begingroup$
@JimB, I think for x, y isn't needed. Thanks for pointing this out. But if I am trying to maximize y, I need to maximize over both the variables since y is an expression of x, right?
$endgroup$
– gaganso
9 hours ago




$begingroup$
@JimB, I think for x, y isn't needed. Thanks for pointing this out. But if I am trying to maximize y, I need to maximize over both the variables since y is an expression of x, right?
$endgroup$
– gaganso
9 hours ago












$begingroup$
Yes, if that's what you want. The general solution appears to be $x = 19762$ and $7230leq y leq 7344$. So to maximize $y$ you'd choose $7344$.
$endgroup$
– JimB
8 hours ago





$begingroup$
Yes, if that's what you want. The general solution appears to be $x = 19762$ and $7230leq y leq 7344$. So to maximize $y$ you'd choose $7344$.
$endgroup$
– JimB
8 hours ago













$begingroup$
@JimB, thank you. But I think the value of $y$ can be greater than 7344 for different values of $x$. For example, at $x = 7504$, the maximum value of y is 13937.
$endgroup$
– gaganso
8 hours ago




$begingroup$
@JimB, thank you. But I think the value of $y$ can be greater than 7344 for different values of $x$. For example, at $x = 7504$, the maximum value of y is 13937.
$endgroup$
– gaganso
8 hours ago










2 Answers
2






active

oldest

votes


















4












$begingroup$

Rationalize the constraint:



constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
0 <= y < 2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-1 Sqrt[
4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <= x <=
19762. &&
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) //
Rationalize[#, 0] & // Simplify;


With the Rationalized constraint you can use Maximize:



maxX = Maximize[x, constraint2, x, y]

(* 19762, x -> 19762, y -> 7287 *)

constraint2 /. maxX[[2]]

(* True *)


EDIT: To find maximum y



(maxY = Maximize[y, constraint2, x, y]) // N


enter image description here



To plot the region defined by the constraint:



reg = ImplicitRegion[constraint2, x, y];

Region[reg,
Frame -> True,
FrameLabel -> (Style[#, 12, Bold] & /@ x, y),
Epilog -> Red,
AbsolutePointSize[3],
Point[x, y /. maxX[[2]]],
Point[x, y /. maxY[[2]]]]


enter image description here






share|improve this answer











$endgroup$




















    2












    $begingroup$

    You have numbers spread a wide range of magnitudes for no good reason. This range is probably too wide for machine precision arithmetic. Also telling NMinimize explicitly that this an integer optimization problem seems to help. Try this:



    constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
    0 <= y <
    2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
    2.8484*10^-1 Sqrt[
    4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <=
    x <= 19762. &&
    2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
    2.8484*10^-1 Sqrt[
    4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
    2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
    2.8484*10^-1 Sqrt[
    4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) // Expand

    maxX = NMaximize[x, constraint2, x, y, Integers,
    MaxIterations -> 10000]



    19762., x -> 19762, y -> 7311




    And with your definition of constraint:



    constraint /. maxX[[2]]



    True







    share|improve this answer











    $endgroup$












    • $begingroup$
      But constraint /. x -> 19762 /. y -> 8647 results in False?
      $endgroup$
      – JimB
      9 hours ago










    • $begingroup$
      @JimB D'oh. Yeah, I did the simplification wrong. -.- Thanks for pointing that out.
      $endgroup$
      – Henrik Schumacher
      9 hours ago











    • $begingroup$
      @HenrikSchumacher, thank you for this. This works for x but when I try to find the maximum y similarly, I still get the same message - NMaximize[y, res, x, y, Integers, MaxIterations -> 100000]. Output: NMaximize::cvdiv: Failed to converge to a solution. The function may be unbounded.
      $endgroup$
      – gaganso
      9 hours ago











    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194684%2fnmaximize-is-not-converging-to-a-solution%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4












    $begingroup$

    Rationalize the constraint:



    constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
    0 <= y < 2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
    2.8484*10^-1 Sqrt[
    4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <= x <=
    19762. &&
    2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
    2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
    2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
    2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) //
    Rationalize[#, 0] & // Simplify;


    With the Rationalized constraint you can use Maximize:



    maxX = Maximize[x, constraint2, x, y]

    (* 19762, x -> 19762, y -> 7287 *)

    constraint2 /. maxX[[2]]

    (* True *)


    EDIT: To find maximum y



    (maxY = Maximize[y, constraint2, x, y]) // N


    enter image description here



    To plot the region defined by the constraint:



    reg = ImplicitRegion[constraint2, x, y];

    Region[reg,
    Frame -> True,
    FrameLabel -> (Style[#, 12, Bold] & /@ x, y),
    Epilog -> Red,
    AbsolutePointSize[3],
    Point[x, y /. maxX[[2]]],
    Point[x, y /. maxY[[2]]]]


    enter image description here






    share|improve this answer











    $endgroup$

















      4












      $begingroup$

      Rationalize the constraint:



      constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
      0 <= y < 2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
      2.8484*10^-1 Sqrt[
      4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <= x <=
      19762. &&
      2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
      2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
      2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
      2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) //
      Rationalize[#, 0] & // Simplify;


      With the Rationalized constraint you can use Maximize:



      maxX = Maximize[x, constraint2, x, y]

      (* 19762, x -> 19762, y -> 7287 *)

      constraint2 /. maxX[[2]]

      (* True *)


      EDIT: To find maximum y



      (maxY = Maximize[y, constraint2, x, y]) // N


      enter image description here



      To plot the region defined by the constraint:



      reg = ImplicitRegion[constraint2, x, y];

      Region[reg,
      Frame -> True,
      FrameLabel -> (Style[#, 12, Bold] & /@ x, y),
      Epilog -> Red,
      AbsolutePointSize[3],
      Point[x, y /. maxX[[2]]],
      Point[x, y /. maxY[[2]]]]


      enter image description here






      share|improve this answer











      $endgroup$















        4












        4








        4





        $begingroup$

        Rationalize the constraint:



        constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
        0 <= y < 2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
        2.8484*10^-1 Sqrt[
        4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <= x <=
        19762. &&
        2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
        2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
        2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
        2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) //
        Rationalize[#, 0] & // Simplify;


        With the Rationalized constraint you can use Maximize:



        maxX = Maximize[x, constraint2, x, y]

        (* 19762, x -> 19762, y -> 7287 *)

        constraint2 /. maxX[[2]]

        (* True *)


        EDIT: To find maximum y



        (maxY = Maximize[y, constraint2, x, y]) // N


        enter image description here



        To plot the region defined by the constraint:



        reg = ImplicitRegion[constraint2, x, y];

        Region[reg,
        Frame -> True,
        FrameLabel -> (Style[#, 12, Bold] & /@ x, y),
        Epilog -> Red,
        AbsolutePointSize[3],
        Point[x, y /. maxX[[2]]],
        Point[x, y /. maxY[[2]]]]


        enter image description here






        share|improve this answer











        $endgroup$



        Rationalize the constraint:



        constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
        0 <= y < 2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
        2.8484*10^-1 Sqrt[
        4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <= x <=
        19762. &&
        2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
        2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
        2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
        2.8484*10^-1 Sqrt[4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) //
        Rationalize[#, 0] & // Simplify;


        With the Rationalized constraint you can use Maximize:



        maxX = Maximize[x, constraint2, x, y]

        (* 19762, x -> 19762, y -> 7287 *)

        constraint2 /. maxX[[2]]

        (* True *)


        EDIT: To find maximum y



        (maxY = Maximize[y, constraint2, x, y]) // N


        enter image description here



        To plot the region defined by the constraint:



        reg = ImplicitRegion[constraint2, x, y];

        Region[reg,
        Frame -> True,
        FrameLabel -> (Style[#, 12, Bold] & /@ x, y),
        Epilog -> Red,
        AbsolutePointSize[3],
        Point[x, y /. maxX[[2]]],
        Point[x, y /. maxY[[2]]]]


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 8 hours ago

























        answered 8 hours ago









        Bob HanlonBob Hanlon

        61.4k33598




        61.4k33598





















            2












            $begingroup$

            You have numbers spread a wide range of magnitudes for no good reason. This range is probably too wide for machine precision arithmetic. Also telling NMinimize explicitly that this an integer optimization problem seems to help. Try this:



            constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
            0 <= y <
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <=
            x <= 19762. &&
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) // Expand

            maxX = NMaximize[x, constraint2, x, y, Integers,
            MaxIterations -> 10000]



            19762., x -> 19762, y -> 7311




            And with your definition of constraint:



            constraint /. maxX[[2]]



            True







            share|improve this answer











            $endgroup$












            • $begingroup$
              But constraint /. x -> 19762 /. y -> 8647 results in False?
              $endgroup$
              – JimB
              9 hours ago










            • $begingroup$
              @JimB D'oh. Yeah, I did the simplification wrong. -.- Thanks for pointing that out.
              $endgroup$
              – Henrik Schumacher
              9 hours ago











            • $begingroup$
              @HenrikSchumacher, thank you for this. This works for x but when I try to find the maximum y similarly, I still get the same message - NMaximize[y, res, x, y, Integers, MaxIterations -> 100000]. Output: NMaximize::cvdiv: Failed to converge to a solution. The function may be unbounded.
              $endgroup$
              – gaganso
              9 hours ago















            2












            $begingroup$

            You have numbers spread a wide range of magnitudes for no good reason. This range is probably too wide for machine precision arithmetic. Also telling NMinimize explicitly that this an integer optimization problem seems to help. Try this:



            constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
            0 <= y <
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <=
            x <= 19762. &&
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) // Expand

            maxX = NMaximize[x, constraint2, x, y, Integers,
            MaxIterations -> 10000]



            19762., x -> 19762, y -> 7311




            And with your definition of constraint:



            constraint /. maxX[[2]]



            True







            share|improve this answer











            $endgroup$












            • $begingroup$
              But constraint /. x -> 19762 /. y -> 8647 results in False?
              $endgroup$
              – JimB
              9 hours ago










            • $begingroup$
              @JimB D'oh. Yeah, I did the simplification wrong. -.- Thanks for pointing that out.
              $endgroup$
              – Henrik Schumacher
              9 hours ago











            • $begingroup$
              @HenrikSchumacher, thank you for this. This works for x but when I try to find the maximum y similarly, I still get the same message - NMaximize[y, res, x, y, Integers, MaxIterations -> 100000]. Output: NMaximize::cvdiv: Failed to converge to a solution. The function may be unbounded.
              $endgroup$
              – gaganso
              9 hours ago













            2












            2








            2





            $begingroup$

            You have numbers spread a wide range of magnitudes for no good reason. This range is probably too wide for machine precision arithmetic. Also telling NMinimize explicitly that this an integer optimization problem seems to help. Try this:



            constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
            0 <= y <
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <=
            x <= 19762. &&
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) // Expand

            maxX = NMaximize[x, constraint2, x, y, Integers,
            MaxIterations -> 10000]



            19762., x -> 19762, y -> 7311




            And with your definition of constraint:



            constraint /. maxX[[2]]



            True







            share|improve this answer











            $endgroup$



            You have numbers spread a wide range of magnitudes for no good reason. This range is probably too wide for machine precision arithmetic. Also telling NMinimize explicitly that this an integer optimization problem seems to help. Try this:



            constraint2 = ((x == 0 && 1. <= y <= 12720.) || (1. <= x <= 10712. && 
            0 <= y <
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2]) || (10713. <=
            x <= 19762. &&
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) -
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2] < y <
            2.08565*10^-36 (3.04959*10^39 + 2.24751*10^34 x) +
            2.8484*10^-1 Sqrt[
            4.98614*10^8 + 4.65469*10^4 x - 3.63201 x^2])) // Expand

            maxX = NMaximize[x, constraint2, x, y, Integers,
            MaxIterations -> 10000]



            19762., x -> 19762, y -> 7311




            And with your definition of constraint:



            constraint /. maxX[[2]]



            True








            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 9 hours ago

























            answered 9 hours ago









            Henrik SchumacherHenrik Schumacher

            59.3k582165




            59.3k582165











            • $begingroup$
              But constraint /. x -> 19762 /. y -> 8647 results in False?
              $endgroup$
              – JimB
              9 hours ago










            • $begingroup$
              @JimB D'oh. Yeah, I did the simplification wrong. -.- Thanks for pointing that out.
              $endgroup$
              – Henrik Schumacher
              9 hours ago











            • $begingroup$
              @HenrikSchumacher, thank you for this. This works for x but when I try to find the maximum y similarly, I still get the same message - NMaximize[y, res, x, y, Integers, MaxIterations -> 100000]. Output: NMaximize::cvdiv: Failed to converge to a solution. The function may be unbounded.
              $endgroup$
              – gaganso
              9 hours ago
















            • $begingroup$
              But constraint /. x -> 19762 /. y -> 8647 results in False?
              $endgroup$
              – JimB
              9 hours ago










            • $begingroup$
              @JimB D'oh. Yeah, I did the simplification wrong. -.- Thanks for pointing that out.
              $endgroup$
              – Henrik Schumacher
              9 hours ago











            • $begingroup$
              @HenrikSchumacher, thank you for this. This works for x but when I try to find the maximum y similarly, I still get the same message - NMaximize[y, res, x, y, Integers, MaxIterations -> 100000]. Output: NMaximize::cvdiv: Failed to converge to a solution. The function may be unbounded.
              $endgroup$
              – gaganso
              9 hours ago















            $begingroup$
            But constraint /. x -> 19762 /. y -> 8647 results in False?
            $endgroup$
            – JimB
            9 hours ago




            $begingroup$
            But constraint /. x -> 19762 /. y -> 8647 results in False?
            $endgroup$
            – JimB
            9 hours ago












            $begingroup$
            @JimB D'oh. Yeah, I did the simplification wrong. -.- Thanks for pointing that out.
            $endgroup$
            – Henrik Schumacher
            9 hours ago





            $begingroup$
            @JimB D'oh. Yeah, I did the simplification wrong. -.- Thanks for pointing that out.
            $endgroup$
            – Henrik Schumacher
            9 hours ago













            $begingroup$
            @HenrikSchumacher, thank you for this. This works for x but when I try to find the maximum y similarly, I still get the same message - NMaximize[y, res, x, y, Integers, MaxIterations -> 100000]. Output: NMaximize::cvdiv: Failed to converge to a solution. The function may be unbounded.
            $endgroup$
            – gaganso
            9 hours ago




            $begingroup$
            @HenrikSchumacher, thank you for this. This works for x but when I try to find the maximum y similarly, I still get the same message - NMaximize[y, res, x, y, Integers, MaxIterations -> 100000]. Output: NMaximize::cvdiv: Failed to converge to a solution. The function may be unbounded.
            $endgroup$
            – gaganso
            9 hours ago

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f194684%2fnmaximize-is-not-converging-to-a-solution%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Францішак Багушэвіч Змест Сям'я | Біяграфія | Творчасць | Мова Багушэвіча | Ацэнкі дзейнасці | Цікавыя факты | Спадчына | Выбраная бібліяграфія | Ушанаванне памяці | У філатэліі | Зноскі | Літаратура | Спасылкі | НавігацыяЛяхоўскі У. Рупіўся дзеля Бога і людзей: Жыццёвы шлях Лявона Вітан-Дубейкаўскага // Вольскі і Памідораў з песняй пра немца Адвакат, паэт, народны заступнік Ашмянскі веснікВ Минске появится площадь Богушевича и улица Сырокомли, Белорусская деловая газета, 19 июля 2001 г.Айцец беларускай нацыянальнай ідэі паўстаў у бронзе Сяргей Аляксандравіч Адашкевіч (1918, Мінск). 80-я гады. Бюст «Францішак Багушэвіч».Яўген Мікалаевіч Ціхановіч. «Партрэт Францішка Багушэвіча»Мікола Мікалаевіч Купава. «Партрэт зачынальніка новай беларускай літаратуры Францішка Багушэвіча»Уладзімір Іванавіч Мелехаў. На помніку «Змагарам за родную мову» Барэльеф «Францішак Багушэвіч»Памяць пра Багушэвіча на Віленшчыне Страчаная сталіца. Беларускія шыльды на вуліцах Вільні«Krynica». Ideologia i przywódcy białoruskiego katolicyzmuФранцішак БагушэвічТворы на knihi.comТворы Францішка Багушэвіча на bellib.byСодаль Уладзімір. Францішак Багушэвіч на Лідчыне;Луцкевіч Антон. Жыцьцё і творчасьць Фр. Багушэвіча ў успамінах ягоных сучасьнікаў // Запісы Беларускага Навуковага таварыства. Вільня, 1938. Сшытак 1. С. 16-34.Большая российская1188761710000 0000 5537 633Xn9209310021619551927869394п

            Partai Komunis Tiongkok Daftar isi Kepemimpinan | Pranala luar | Referensi | Menu navigasidiperiksa1 perubahan tertundacpc.people.com.cnSitus resmiSurat kabar resmi"Why the Communist Party is alive, well and flourishing in China"0307-1235"Full text of Constitution of Communist Party of China"smengembangkannyas

            ValueError: Expected n_neighbors <= n_samples, but n_samples = 1, n_neighbors = 6 (SMOTE) The 2019 Stack Overflow Developer Survey Results Are InCan SMOTE be applied over sequence of words (sentences)?ValueError when doing validation with random forestsSMOTE and multi class oversamplingLogic behind SMOTE-NC?ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)SmoteBoost: Should SMOTE be ran individually for each iteration/tree in the boosting?solving multi-class imbalance classification using smote and OSSUsing SMOTE for Synthetic Data generation to improve performance on unbalanced dataproblem of entry format for a simple model in KerasSVM SMOTE fit_resample() function runs forever with no result