Maximum

William Fish's picture

Why isn't answer (2) the same as answer (4) in the following:

View 4937_Page 2.mw on MapleNet or Download 4937_Page 2.mw
View file details

This is from page 2 of When Least Is Best by Paul J. Nahin.

Comments

typo and use eval

There are two problems with (2). First, Rootof is misspelled, it should be RootOf.  Second, y is an expression, not a function (procedure); to evaluate it you should use eval.

evalf(eval(y,x=RootOf(v,0.1)));
                                 5.781103189

William Fish's picture

Maximize

Joe,

Thank you.

Now I have another problem.  I don't understand how maximize works.  WARNING, the last line of the following Maple worksheet runs forever (at least on my PC):

View 4937_Page 2 Joe Riel.mw on MapleNet or Download 4937_Page 2 Joe Riel.mw
View file details

The offending line is:

maximize(y, x = 0 .. 1)

Can anybody help me understand how maximize works or do I need a faster PC?

"The Cray-3 is so fast it can execute an infinite loop in under 2 seconds!"

Try Optimization:-Maximize

The statements in question are

y := 3*cos(4*Pi*x-1.3)+5*cos(2*Pi*x+0.5);
maximize(y, x=0..1);

I don't think a faster computer will help much.  To see this, you could do the following with command line maple (I wouldn't do this in the Standard GUI, since its output bogs down)

printlevel := 100:
maximize(y, x=0..1);

On a linux box, or with cygwin on Windows, you might try, from a shell

$ cat << EOF | maple -q | sed -n '/enter\|exit/p' | more
> y := 3*cos(4*Pi*x-1.3)+5*cos(2*Pi*x+0.5);
> printlevel := 100:
> maximize(y, x=0..1);
> EOF

To solve this problem you can do
 

Optimization:-Maximize(y,x=0..1);
                                 [2.01681169665899551, [x = 0.681550998912437866]]


 

 

acer's picture

local or global optimum

The value x=0.68 returned from Optimization:-Maximize(y,x=0..1) is a local optimum. The graph of y, plot(y, x=0..1), shows that.

y := 3*cos(4*Pi*x-1.3)+5*cos(2*Pi*x+0.5);
plot(y, x=0..1);
Optimization:-Maximize(y,x=0..1,method=branchandbound);
plot(y, x=0..0.1);

acer

Axel Vogt's picture

manually



splitting the periodics manually also works

Optimization:-Maximize(y,x=0..1/2);

          [5.78110318870717600, [x = 0.0512129818925790292]]

Axel Vogt's picture

a symbolic solution

Changing periodics to 2*Pi and taking the derivative one wants the zeros of
-6*sin(2*xi-13/10)-5*sin(xi+1/2), where the first zero stands for the maximum.

The following is a symbolic solution for it (but my Maple falls into agony
if trying to convert that to Reals only), check it by numerical evaluation.

May be I say a bit more about that later.
-I*ln(I*(1/24*((-50*(cos(1)+I*sin(1))^(23/5)*(-202\
5*(cos(1)+I*sin(1))^(23/5)+2025*(cos(1)+I*sin(1))^\
(46/5)+3*(4144227*(cos(1)+I*sin(1))^(69/5)+455625*\
(cos(1)+I*sin(1))^(46/5)+455625*(cos(1)+I*sin(1))^\
(92/5))^(1/2))^(1/3)*((-25*(cos(1)+I*sin(1))^(23/5\
)*(-2025*(cos(1)+I*sin(1))^(23/5)+2025*(cos(1)+I*s\
in(1))^(46/5)+3*(4144227*(cos(1)+I*sin(1))^(69/5)+\
455625*(cos(1)+I*sin(1))^(46/5)+455625*(cos(1)+I*s\
in(1))^(92/5))^(1/2))^(1/3)+8*(-2025*(cos(1)+I*sin\
(1))^(23/5)+2025*(cos(1)+I*sin(1))^(46/5)+3*(41442\
27*(cos(1)+I*sin(1))^(69/5)+455625*(cos(1)+I*sin(1\
))^(46/5)+455625*(cos(1)+I*sin(1))^(92/5))^(1/2))^\
(2/3)-2856*(cos(1)+I*sin(1))^(23/5))/(-2025*(cos(1\
)+I*sin(1))^(23/5)+2025*(cos(1)+I*sin(1))^(46/5)+3\
*(4144227*(cos(1)+I*sin(1))^(69/5)+455625*(cos(1)+\
I*sin(1))^(46/5)+455625*(cos(1)+I*sin(1))^(92/5))^\
(1/2))^(1/3))^(1/2)-8*((-25*(cos(1)+I*sin(1))^(23/\
5)*(-2025*(cos(1)+I*sin(1))^(23/5)+2025*(cos(1)+I*\
sin(1))^(46/5)+3*(4144227*(cos(1)+I*sin(1))^(69/5)\
+455625*(cos(1)+I*sin(1))^(46/5)+455625*(cos(1)+I*\
sin(1))^(92/5))^(1/2))^(1/3)+8*(-2025*(cos(1)+I*si\
n(1))^(23/5)+2025*(cos(1)+I*sin(1))^(46/5)+3*(4144\
227*(cos(1)+I*sin(1))^(69/5)+455625*(cos(1)+I*sin(\
1))^(46/5)+455625*(cos(1)+I*sin(1))^(92/5))^(1/2))\
^(2/3)-2856*(cos(1)+I*sin(1))^(23/5))/(-2025*(cos(\
1)+I*sin(1))^(23/5)+2025*(cos(1)+I*sin(1))^(46/5)+\
3*(4144227*(cos(1)+I*sin(1))^(69/5)+455625*(cos(1)\
+I*sin(1))^(46/5)+455625*(cos(1)+I*sin(1))^(92/5))\
^(1/2))^(1/3))^(1/2)*(-2025*(cos(1)+I*sin(1))^(23/\
5)+2025*(cos(1)+I*sin(1))^(46/5)+3*(4144227*(cos(1\
)+I*sin(1))^(69/5)+455625*(cos(1)+I*sin(1))^(46/5)\
+455625*(cos(1)+I*sin(1))^(92/5))^(1/2))^(2/3)+285\
6*((-25*(cos(1)+I*sin(1))^(23/5)*(-2025*(cos(1)+I*\
sin(1))^(23/5)+2025*(cos(1)+I*sin(1))^(46/5)+3*(41\
44227*(cos(1)+I*sin(1))^(69/5)+455625*(cos(1)+I*si\
n(1))^(46/5)+455625*(cos(1)+I*sin(1))^(92/5))^(1/2\
))^(1/3)+8*(-2025*(cos(1)+I*sin(1))^(23/5)+2025*(c\
os(1)+I*sin(1))^(46/5)+3*(4144227*(cos(1)+I*sin(1)\
)^(69/5)+455625*(cos(1)+I*sin(1))^(46/5)+455625*(c\
os(1)+I*sin(1))^(92/5))^(1/2))^(2/3)-2856*(cos(1)+\
I*sin(1))^(23/5))/(-2025*(cos(1)+I*sin(1))^(23/5)+\
2025*(cos(1)+I*sin(1))^(46/5)+3*(4144227*(cos(1)+I\
*sin(1))^(69/5)+455625*(cos(1)+I*sin(1))^(46/5)+45\
5625*(cos(1)+I*sin(1))^(92/5))^(1/2))^(1/3))^(1/2)\
*(cos(1)+I*sin(1))^(23/5)+2880*I*(cos(1)+I*sin(1))\
^(23/10)*(-2025*(cos(1)+I*sin(1))^(23/5)+2025*(cos\
(1)+I*sin(1))^(46/5)+3*(4144227*(cos(1)+I*sin(1))^\
(69/5)+455625*(cos(1)+I*sin(1))^(46/5)+455625*(cos\
(1)+I*sin(1))^(92/5))^(1/2))^(1/3)-250*I*(cos(1)+I\
*sin(1))^(69/10)*(-2025*(cos(1)+I*sin(1))^(23/5)+2\
025*(cos(1)+I*sin(1))^(46/5)+3*(4144227*(cos(1)+I*\
sin(1))^(69/5)+455625*(cos(1)+I*sin(1))^(46/5)+455\
625*(cos(1)+I*sin(1))^(92/5))^(1/2))^(1/3))/(-2025\
*(cos(1)+I*sin(1))^(23/5)+2025*(cos(1)+I*sin(1))^(\
46/5)+3*(4144227*(cos(1)+I*sin(1))^(69/5)+455625*(\
cos(1)+I*sin(1))^(46/5)+455625*(cos(1)+I*sin(1))^(\
92/5))^(1/2))^(1/3)/((-25*(cos(1)+I*sin(1))^(23/5)\
*(-2025*(cos(1)+I*sin(1))^(23/5)+2025*(cos(1)+I*si\
n(1))^(46/5)+3*(4144227*(cos(1)+I*sin(1))^(69/5)+4\
55625*(cos(1)+I*sin(1))^(46/5)+455625*(cos(1)+I*si\
n(1))^(92/5))^(1/2))^(1/3)+8*(-2025*(cos(1)+I*sin(\
1))^(23/5)+2025*(cos(1)+I*sin(1))^(46/5)+3*(414422\
7*(cos(1)+I*sin(1))^(69/5)+455625*(cos(1)+I*sin(1)\
)^(46/5)+455625*(cos(1)+I*sin(1))^(92/5))^(1/2))^(\
2/3)-2856*(cos(1)+I*sin(1))^(23/5))/(-2025*(cos(1)\
+I*sin(1))^(23/5)+2025*(cos(1)+I*sin(1))^(46/5)+3*\
(4144227*(cos(1)+I*sin(1))^(69/5)+455625*(cos(1)+I\
*sin(1))^(46/5)+455625*(cos(1)+I*sin(1))^(92/5))^(\
1/2))^(1/3))^(1/2))^(1/2)+1/24*((-25*(cos(1)+I*sin\
(1))^(23/5)*(-2025*(cos(1)+I*sin(1))^(23/5)+2025*(\
cos(1)+I*sin(1))^(46/5)+3*(4144227*(cos(1)+I*sin(1\
))^(69/5)+455625*(cos(1)+I*sin(1))^(46/5)+455625*(\
cos(1)+I*sin(1))^(92/5))^(1/2))^(1/3)+8*(-2025*(co\
s(1)+I*sin(1))^(23/5)+2025*(cos(1)+I*sin(1))^(46/5\
)+3*(4144227*(cos(1)+I*sin(1))^(69/5)+455625*(cos(\
1)+I*sin(1))^(46/5)+455625*(cos(1)+I*sin(1))^(92/5\
))^(1/2))^(2/3)-2856*(cos(1)+I*sin(1))^(23/5))/(-2\
025*(cos(1)+I*sin(1))^(23/5)+2025*(cos(1)+I*sin(1)\
)^(46/5)+3*(4144227*(cos(1)+I*sin(1))^(69/5)+45562\
5*(cos(1)+I*sin(1))^(46/5)+455625*(cos(1)+I*sin(1)\
)^(92/5))^(1/2))^(1/3))^(1/2)+5/24*I*cos(23/10)-5/\
24*sin(23/10)))-1/2;
William Fish's picture

Symbolic Solution

How did you make that?

Can you upload a Maple worksheet that I can download?

I don't understand "changing periodics".

William Fish's picture

Global

Acer,

You make it look easy.  Thank you.

curious

I find it interesting that method=branchandbound works here.  I would never have found that from reading the help page for Optimization[Maximize]. The Optimization,Options help page doesn't suggest that this option is available for  Minimize/Maximize, but imply it is for LPSolve and NLPSolve.

acer's picture

options passed through

I thought that Maximize/Minimize passed options through (here, to NLPSolve).

acer

yes

You are correct, as mention in the last bullet of the Description section:

- The Minimize and Maximize commands call one of the Optimization[LPSolve], 
  Optimization[QPSolve] or Optimization[NLPSolve] commands, depending on the
  form of the input.

I should read the entire help page before complaining.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}