# How can I show multiple PDFs derived from my distribution in one plot

My question is related to the This question. I want to plot different PDFs for a given random variable in the same plot using f[x_NumericQ].

For example, I have tried to evaluate the following code for different values of $$\mu$$ and $$\sigma > 1$$ to get differents PDFs in the same plot, but I can't. I only can only plot it for one fixed parameter.

Code:

μ = 0.5;
f[z_?NumericQ] :=
NIntegrate[
Exp[-z^2]* Erf[(z-μ)/(Sqrt*σ)]* Erfi[(z-μ)/(Sqrt*σ)], {σ, 1, ∞}]
Dist = ProbabilityDistribution[f[z], {z, -∞, ∞}];
pdfH[z_] := PDF[Dist, z];
Plot[pdfH[z], {z, -5, 5}]


How can I plot different PDFs related to my distribution in the same plot using a different color to distinguish each PDF?

Note: $$\mu \in [0, 1),\,\sigma >1$$

• The linked question has an accepted answer, so you will need to tell us more about your problem and specifically what you have tried and what issues you are running into in your own problem that are not solved by that answer. Note also that the correct syntax is F[x_?NumericQ] (with the ?). – MarcoB Dec 3 '19 at 17:08
• For example I want to plot differents PDF in the same plot by varaiations of parameters like mean value ,..., For example in the linked questions The Given plot is for fixed parameters value , How I can use F[x_?NumericQ] for Mu=0.5, ,0.4,0.3,..... and the same with others plot to get differents plot in one plot – zeraoulia rafik Dec 3 '19 at 17:19
• Can you please provide an example of the pdf you want to plot, with different parameter values. The example you refer to is non-standard: it is about a pdf that cannot be expressed in a closed-form. Your problem sounds much simpler. – wolfies Dec 3 '19 at 17:21
• Ok, Wait I add it to the question now – zeraoulia rafik Dec 3 '19 at 17:31
• And what makes you think that that function, integrating over $\sigma$, is a (valid) pdf? – wolfies Dec 3 '19 at 18:44

To evaluate the function that you derive as the PDF of f for multiple values of μ, it is a good idea to make it depend on μ as well as z; like so:

f[z_?NumericQ, μ_?NumericQ] := NIntegrate[Exp[-z^2] Erf[(z - μ)/(σ Sqrt)]^2, {σ, 1, ∞}]


Now I alter the defintion you give for the PDF function to return a pure function parametrized by μ

pdfF[μ_?NumericQ] := PDF[ProbabilityDistribution[f[x, μ], {x, -∞, ∞}]]


Now a plot with μ ranging over a subdivision of the unit interval can be made like this:

With[{n = 3},
Show[
Plot[
Labeled[pdfF[#1][z], Row[{"μ = ", Rationalize[#1]}], Above], {z, -5, 5},
PlotRange -> All,
PlotStyle -> #2] &
@@@
Rest[{#, Hue[#]} & /@ Subdivide[0., 1., n]],
ImageSize -> Large]] After seeing plot, I don't have any confidence that pdfF is a valid PDF.

### Update

The OP points out in a comment that I made an error when I thought I could simplify the definition of f. I use the correct definition here.

f[z_?NumericQ, μ_?NumericQ] :=
NIntegrate[Exp[-z^2] Erf[(z - μ)/(σ Sqrt)] Erfi[(z - μ)/(σ Sqrt)], {σ, 1, ∞}]


The rest of the code given a above is still valid , but here is an improved plotting expression.

With[{n = 3},
Show[
Plot[Labeled[pdfF[#1][z], Row[{"μ = ", #1}], Above], {z, -5, 5},
PlotRange -> All,
PlotStyle -> #2] &
@@@
({#, Hue[#]} & /@ (Range[n]/n)),
ImageSize -> Large]] It doesn't look much different and, more importantly, consider this;

With[{n = 3}, NIntegrate[pdfF[#][z], {z, -5, 5}] & /@ (Range[n]/n)]


{0.707847, 1.11662, 1.83429}`

The integral of a PDF over its domain should be 1, so my conclusion is still the your PDF formulation is wrong.

• Thanks for that , PLeas how you know that is not a valid PDF ? – zeraoulia rafik Dec 4 '19 at 10:11
• Pleas The function you took is not the same as above in my question the first function is error function and in the second is imaginarry error function erfi(z) – zeraoulia rafik Dec 4 '19 at 10:48
• I have adjusted it I have got {0.98..,0.98,0.98...,0.98..} ,for n=4, I s this a valid PDF , i have used your last command – zeraoulia rafik Dec 5 '19 at 1:07
• I have got this exactly :{0.981171,0.980972,0.980627,0.980114,0.979407,0.978465,0.97724,0.975674,0.973696} – zeraoulia rafik Dec 5 '19 at 1:11