# Find a maximum of the following function using Grid Search?

**URL:** <https://community.wolfram.com/t/find-a-maximum-of-the-following-function-using-grid-search/12311>\
**Category:** Questions\
**Tags:** mathematica, algebra, equation-solving, optimization, numerical-computation, statistics-and-probability\
**Created:** [April 13, 2018, 1:03am UTC](https://community.wolfram.com/t/find-a-maximum-of-the-following-function-using-grid-search/12311 "2018-04-13T01:03:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![c860113](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@c860113](https://community.wolfram.com/u/c860113)\
**Post date:** [April 13, 2018, 1:03am UTC](https://community.wolfram.com/t/find-a-maximum-of-the-following-function-using-grid-search/12311/1 "2018-04-13T01:03:22Z")

</div>

[![enter image description here](https://i.stack.imgur.com/vl0gw.png)](https://i.stack.imgur.com/vl0gw.png)

I would like to find the maximum value and the optimal m\_a and m\_d from the above two functions using GRID search. I have tried but it doesn’t work. Do you have any ideas? Any different example of the function with the code would also be great.

```
f = Integrate[PDF[NormalDistribution[10*Subscript[m, d], 1*Subscript[m, d]], Subscript[c,i]] * (Subscript[m, d]*Subscript[c, i] - 10) * (1-CDF[NormalDistribution[10*Subscript[m, a], 2*Subscript[m, a]], Subscript[c, i]]), {Subscript[c, i], -Infinity, Infinity}]; 
g = Integrate[PDF[NormalDistribution[10*Subscript[m, a], 2*Subscript[m, a]], Subscript[c,i]] * (Subscript[m, a]*Subscript[c, i] - 10) * (1-CDF[NormalDistribution[10*Subscript[m, d], 1*Subscript[m, a]], Subscript[c, i]]), {Subscript[c, i], -Infinity, Infinity}];

NMaximize[f, {Subscript[m, d], Subscript[m, a]},Method -> {"RandomSearch"}];
NMaximize[g, {Subscript[m, d], Subscript[m, a]},Method -> {"RandomSearch"}];

```

The results show just f and g. It doesn’t work for NMaximize. The screenshot is as follows:

[![enter image description here](https://i.stack.imgur.com/yqW7V.png)](https://i.stack.imgur.com/yqW7V.png)

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [April 13, 2018, 3:36pm UTC](https://community.wolfram.com/t/find-a-maximum-of-the-following-function-using-grid-search/12311/2 "2018-04-13T15:36:20Z")

</div>

It’s not clear what you’re trying to do, since you’ve got NSolve around something that doesn’t look like an equation. Maybe you want NIntegrate instead NSolve around Integrate.

---

<div class="post-metadata">

**Author:** ![c860113](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@c860113](https://community.wolfram.com/u/c860113)\
**Post date:** [April 15, 2018, 6:14am UTC](https://community.wolfram.com/t/find-a-maximum-of-the-following-function-using-grid-search/12311/3 "2018-04-15T06:14:41Z")

</div>

Thank you Frank, I just edited the equations to make it clear. Do you have any ideas?

---

<div class="post-metadata">

**Author:** ![fkampas](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/fkampas/32/41217_2.png) [@fkampas](https://community.wolfram.com/u/fkampas)\
**Post date:** [April 15, 2018, 12:20pm UTC](https://community.wolfram.com/t/find-a-maximum-of-the-following-function-using-grid-search/12311/4 "2018-04-15T12:20:46Z")

</div>

Have you tested to see if the integrals work for numerical values of md and ma ?
