# Solve a function to find the optimum value of parameter in mathematica [duplicate]

I have a complicated function as shown

It doesn't have a standard integration as far as I know.

Now, numerical integration of the left hand side function over a set of points gives the right hand side value (sorry about the missing integration sign in the image).

I know the value of parameter $X0$ as constant and $x$ is the independent variable. I wish to extract parameter alpha which I know is a real number.

How shall I do that in Mathematica? I have tried FindRoot method,didn't work.

FindRoot[(NIntegrate[(Abs[
0.5*Sqrt[Pi/(alpha)]*
Exp[-((Pi*x)^2/(alpha))]*(1 -
Erf[(-32.3077)*Sqrt[(alpha)] +
I*Pi*x/Sqrt[(alpha)]])])^2, {x, 0.00081846, 0.000818573,
0.000818686, 0.0008188, 0.000818913, 0.000819026, 0.000819139,
0.000819253, 0.000819366, 0.000819479, 0.000819592, 0.000819706,
0.000819819, 0.000819932, 0.000820045, 0.000820159, 0.000820272,
0.000820385, 0.000820498, 0.000820612, 0.000820725, 0.000820838,
0.000820951, 0.000821065, 0.000821178, 0.000821291, 0.000821404,
0.000821518, 0.000821631, 0.000821744, 0.000821857, 0.000821971,
0.000822084, 0.000822197, 0.00082231, 0.000822424, 0.000822537,
0.00082265, 0.000822763, 0.000822877, 0.00082299, 0.000823103,
0.000823216, 0.00082333, 0.000823443, 0.000823556, 0.000823669,
0.000823783, 0.000823896, 0.000824009, 0.000824122, 0.000824236,
0.000824349, 0.000824462, 0.000824575, 0.000824689, 0.000824802,
0.000824915, 0.000825028}]) == 0.0139828, {alpha, 0.001}]


$X0$ for a particular case is -32.3077, becomes $0$ for particular $x$ and varies upto +30.3699 for different cases.

'alpha' for that particular X0 should come around 0.03 and thus alpha varies with $X0$

• 1) Add code to your question rather than an image. 2) Show us what you have tried so far, and why it didn't work. 3) Add the values of the constants in your expression. 4) what are the limits of integration? – MarcoB Sep 2 '15 at 19:33
• @MarcoB thanks for the reply, I have added my code sample kindly help me out. I hope I have addressed your requirements. – AVyas Sep 3 '15 at 8:42
• Links to answers for this issue are found in the section on NumericQ of this Q&A: What are the most common pitfalls awaiting new users? – Jens Sep 3 '15 at 17:05
• @Jens I thought of using f[alpha_?NumericQ, x_?NumericQ] := Abs[0.5*Sqrt[Pi/alpha]*Exp[-(Pi*x)^2/alpha]*(1 - Erf[-32.3077*Sqrt[alpha] + I*Pi*x/Sqrt[alpha]])]^2 followed by FindRoot[NIntegrate[f[alpha, x], ... in my answer, but the error message persisted. Of course, even the code in the question gives the correct answer despite the error message. – bbgodfrey Sep 3 '15 at 17:21
• I found another possible duplicate (this type of issue is so common that answers are scattered throughout this site): How can I get Mathematica to allow me to apply FindRoot to an expression that contains NIntegrate?. I think it's better not to add to this proliferation, so I still propose to close this question. – Jens Sep 3 '15 at 17:29

Adding the option, Evaluated -> False tells FindRoot not to evaluate the function (NIntegrate in this case) before inserting alpha.

FindRoot[NIntegrate[Abs[0.5*Sqrt[Pi/alpha]*Exp[-(Pi*x)^2/alpha]*(1 -
Erf[-32.3077*Sqrt[alpha] + I*Pi*x/Sqrt[alpha]])]^2,
{x, 0.00081846, 0.000818573,
0.000818686, 0.0008188, 0.000818913, 0.000819026, 0.000819139,
0.000819253, 0.000819366, 0.000819479, 0.000819592, 0.000819706,
0.000819819, 0.000819932, 0.000820045, 0.000820159, 0.000820272,
0.000820385, 0.000820498, 0.000820612, 0.000820725, 0.000820838,
0.000820951, 0.000821065, 0.000821178, 0.000821291, 0.000821404,
0.000821518, 0.000821631, 0.000821744, 0.000821857, 0.000821971,
0.000822084, 0.000822197, 0.00082231, 0.000822424, 0.000822537,
0.00082265, 0.000822763, 0.000822877, 0.00082299, 0.000823103,
0.000823216, 0.00082333, 0.000823443, 0.000823556, 0.000823669,
0.000823783, 0.000823896, 0.000824009, 0.000824122, 0.000824236,
0.000824349, 0.000824462, 0.000824575, 0.000824689, 0.000824802,
0.000824915, 0.000825028}] == 0.0139828, {alpha, 0.001},
Evaluated -> False]

(* {alpha -> 0.00132634} *)


Incidentally, the expression in the question contains many unnecessary pairs of parentheses. Although not harmful, they make the expression longer and, for me, more difficult to read.