Message Boards Message Boards

0
|
3777 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Max length of a function during Maximize

Posted 4 years ago

Hi, I'm trying to solve a global constrained non-linear optimization problem with Wolfram but it's not working as expected for me. I tried with a simplified version of my problem and I reached a point when it fails to correctly recognize the type of problem. For example if I paste in the api explorer here https://products.wolframalpha.com/api/explorer/ the following code it works properly:

NMaximize[{3.6027769090403445*1e-52*a^3 + 9.73306257869222*1e-52*a^2*b + (-3.1793546987662064)*1e-67*a^2 + 6.968194393839056*1e-52*a*b^2, a >= 0 && b >=0 && a + b == 290015693412189845814109}, {a, b}]

If instead I add just one monomial to the function to maximize, 5.7587424928741081e-75a*b in this case, it fails to recognize the problem correctly as it's suggesting me "NMaximize 3.6027769090403445"

NMaximize[{3.6027769090403445*1e-52*a^3 + 9.73306257869222*1e-52*a^2*b + (-3.1793546987662064)*1e-67*a^2 + 6.968194393839056*1e-52*a*b^2 + 5.758742492874108*1e-75*a*b, a >= 0 && b >=0 && a + b == 290015693412189845814109}, {a, b}]

Are there limitations on the input size?

Thanks in advance.

POSTED BY: W B
4 Replies
Anonymous User
Anonymous User
Posted 4 years ago

I tried your function and numerical precision and accuracy limits were exceeded. You can alleviate this by raising the same (see Help) or using base numbers with higher accuracy and precision (more digits) or by using arbitrary precision numbers. (it's suggested you always use arbitrary precision at all times unless limited accuracy and precision, including error of calculations, are to be calculated intentionally). Next note I zero'ed some of the last digits of "a+b". This is due to calculation errors that Mathematica tracks on each +, -, /, *.

In[404]:= NMaximize[{3.6027769090403445 10^(-52) a^3 + 
   9.73306257869222 10^(-52) a^2 b + -3.1793546987662064 10^(-67) a^2 \
+ 6.968194393839056 10^(-52) a b^2, 
  a >= 0 && b >= 0 && a + b == 290015693412189000000000}, {a, b}]

Out[404]= {8.78824*10^18, {a -> 2.90016*10^23, b -> 0.}}

In[401]:= Maximize[{Rationalize[3.6027769090403445 10^(-52), 
     10^(-52)] a^3 + 
   Rationalize[9.73306257869222 10^(-52), 10^(-52)] a^2 b + 
   Rationalize[-3.1793546987662064 10^(-67), 10^(-67)] a^2 + 
   Rationalize[6.968194393839056 10^(-52), 10^(-52)] a b^2, 
  a >= 0 && b >= 0 && a + b == 290015693412189845814109}, {a, b}]

Out[401]= \
{415916158542085055402727940040315199561430548561835112571162290342123\
8795019140734549704991222017851010872571220634013/
  47326449583022447216549007278772095603881176748731854250575980000411\
7209146543199805755858639388672, {a -> 290015693412189845814109, 
  b -> 0}}

I hope that helps you search where in Help you can look to resolve your question. And yes the N in NMaximize does mean calculations will have a limited width, ie, FindRoot[x^2 - 2, {x, 1}, WorkingPrecision -> 60]. Ultimately when you use "numeric approximation" functions that are built to take advantage of built-in math in your CPU, they will be limited and fail, and to get around this limit you must forego math-chip acceleration. The subject of rounding error correctly during programs is an involved one - it's suggested you use arbitrary precision where possible except when printing final results in decimal digits.

POSTED BY: Anonymous User
Posted 4 years ago

Thanks Jhon for your answer.

I tried your solution, pasted right below, but got the same error as before (input not interpreted correctly). Any idea why?

Maximize[{Rationalize[3.6027769090403445 *10^(-52), 10^(-52)] * a^3 + Rationalize[9.73306257869222 * 10^(-52), 10^(-52)] * a^2 * b + Rationalize[-3.1793546987662064 * 10^(-67), 10^(-67)] * a^2 + Rationalize[6.968194393839056*10^(-52), 10^(-52)] * a * b^2,  a >= 0 && b >= 0 && a + b == 290015693412189845814109}, {a, b}]

I also tried with higher precision numbers (made some scaling) and using Maximize instead of NMaximize

Maximize[{0.0000000000000000016199782531366518*a^3 + 0.00000000000000011026205710738453*a^2*b + 0.00000000000000000000038565619554281564*a^2 + 0.0000000000000002420364999206427*a*b^2 + 0.000000000
000000000001214369409221946*a*b + 0.0000000000000000000000000055152713787316975*a + 0.00000000000000007521769560967158*b^3 + 0.0000000000000000000010935718648676767*b^2 + 0.0000000000000000000000000079
55449222325909*b + 0.00000000000000000000000000000004643343179177092*1, a >= 0 && b >= 0 && a + b = 290108.227655164058675972}, {a, b}]

In the real problem I have a third degree polynomial with 56 monomials on 5 variables, is it able to handle it?

POSTED BY: W B

What specifically is meant by "input not interpreted correctly"? Is this being done in Mathematica, or Wolfram|Alpha?

POSTED BY: Daniel Lichtblau
Posted 4 years ago

I was using the Wolfram Alpha Full Results API, but it's the same on the website

enter image description here

It's not interpreting the input correctly.

POSTED BY: W B
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract