I am very new to Mathematica programming and am trying to find the optimum of a numerical integral for various values of a parameter. Here is the basic code for one parameter value that runs fine - I have defined a list of values for the parameter, p2g:
cl = 0;
ch = 1;
el = -.1;
eh = .1;
F[e_] = Max[0, Min[(e - el)/(eh - el), 1]];
d = .1;
pi = .2;
p2g = .05 Array[# &, 6];
p1sg = ConstantArray[0, 6];
i = 1;
Obj1[p_?NumericQ] :=
NIntegrate[(c + d - p) (1 - F[(1 - pi) p2g[[i]] + pi c - p]), {c,
cl, p2g[[i]]}] +
NIntegrate[(c + d - p) (1 - F[c - p]), {c, p2g[[i]], ch}];
p1s = p /. Last[NMaximize[{Obj1[p]}, {p}]];
p1sg[[i]] = p1s;
My naive way of doing this was to put the whole thing in a for loop and change $ i$. Once I do this, the code returns an error. basically it cannot assign the value in NMaximize. Does anyone know how to deal with this.
Thanks.
Table
. Also, your code simply cannot run because it has several syntax errors, for instance missing semicolons at the end of every line. Also, please show all necessary code, such as your definitions ofF
,p2g
, etc. $\endgroup$ – David G. Stork Jan 27 '16 at 19:33NIntegrate
, one must assign numerical values to all quantities. Here,pi
andp2g
are undefined. This needs to be corrected. $\endgroup$ – bbgodfrey Jan 27 '16 at 19:34pi
andp2g
are defined before $\endgroup$ – Ali Jan 27 '16 at 19:35