Message Boards Message Boards

Integrate inside an NMinimize?

Posted 8 years ago
POSTED BY: Parth Nagarkar
Posted 8 years ago

When you aren't certain whether the integration can work inside NMinimize and your integral is simple enough then just pull the integration outside the NMinimize.

In[1]:= int = 
 Integrate[
   1 - (E^(-c*Subscript[k, 1]/w*r))^Subscript[a, 1]* (E^(-c*Subscript[k, 2]/w*r))^Subscript[a, 2]*
     (E^(-c*Subscript[k, 3]/w*r))^Subscript[a, 3]* (E^(-c*Subscript[k, 4]/w*r))^Subscript[a, 4],
     {r, Subscript[r, q], Subscript[r, q2]}] /.
     {w->3140, Subscript[k,1]->34, Subscript[k,2]->27, Subscript[k,3]->20,
      Subscript[k,4]->14, c->0.79788456, Subscript[r,q]->475, Subscript[r,q2]->1200}

Out[1]= 725 - (3935.41 (-0.0000314404^Subscript[a,1] 0.000265751^Subscript[a,2]
     0.00224628^Subscript[a,3] 0.0139967^Subscript[a,4] + 0.0165103^Subscript[a,1]
     0.0384316^Subscript[a,2]0.0894584^Subscript[a,3] 0.184559^Subscript[a,4]))/
    (34 Subscript[a,1] + 27 Subscript[a,2] + 20 Subscript[a,3] + 14 Subscript[a,4])

Next, I don't see in the documentation that you can simply declare 'Integers', as you can do in a few other functions. I do see that you can declare that particular variables are in the domain of Integers. I will skip that for the moment and look at the minimization

In[2]:= NMinimize[{int, {Subscript[a,1]>=0, Subscript[a,2]>=0, Subscript[a,3]>=0, Subscript[a,4]>=0, 
   Subscript[a,1]+Subscript[a,2]+Subscript[a,3]+Subscript[a,4]==100}},
   {Subscript[a,1], Subscript[a,2], Subscript[a,3], Subscript[a,4]}]

During evaluation of In[2]:= NMinimize::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations. >>

Out[2]= {725., {Subscript[a,1]->90.2067, Subscript[a,2]->4.37246, Subscript[a,3]->2.76843, Subscript[a,4]->2.65242}}

The warning about convergence might not be serious. This is likely because of the precision of the parameters that you have used.

This is not a complete solution to your problem, but perhaps you can adapt this to get where you need to go.

POSTED BY: Bill Simpson
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