Message Boards Message Boards

0
|
3764 Views
|
8 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Visualize two consecutive definite integrals?

Posted 9 years ago

Dear Wolfram Community,

I have a formula, and would like to visualize it. The formula consists of two consecutive integrations. I defined my formula with embedded Integrate commands in Wolfram Mathematica, but I got numerous error messages. I also tried with NIntegrate command, with the "?NumericQ" hint, but nothing changed.

Here is my code with the error messages:

Clear["Global`*"]

(*$MaxExtraPrecision=50*)

In[212]:= Integrate[
 Integrate[
  G1[t - \[Gamma][x, k] - T]/(T*Sqrt[k*(1 - k)]), {T, -\[Beta][x, k], 
   t - \[Gamma][x, k]}], {k, 0, 1}]

Out[212]= \!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\), \(1\)]\(\((
\*SubsuperscriptBox[\(\[Integral]\), \(-\[Beta][x, 
       k]\), \(t - \[Gamma][x, k]\)]
\*FractionBox[\(G1[t - T - \[Gamma][x, k]]\), \(
\*SqrtBox[\(\((1 - 
           k)\)\ k\)]\ T\)] \[DifferentialD]T)\) \[DifferentialD]k\)\)

cons1 = -1/Sqrt[33];
cons2 = 808/(99*Sqrt[33]);
cons3 = 128/(99*Sqrt[33]);
cons4 = 2/Sqrt[33];

In[217]:= \[Gamma][x_, k_] = 
  cons1*(1 - 2*k)*x + cons2*k + cons3*Log[k/(1 - k)];
\[Beta][x_, k_] = (cons4*x + cons2)*k;

In[219]:= G1[t_] = Exp[-(t)^2];

In[220]:= 
u[t_, x_] = 
 Integrate[
  Integrate[
   G1[t - \[Gamma][x, k] - T]/(T*Sqrt[k*(1 - k)]), {T, -\[Beta][x, k],
     t - \[Gamma][x, k]}], {k, 0, 1}];

In[221]:= Plot[u[0, x], {x, -10, 10}, PlotRange -> Automatic]

During evaluation of In[221]:= NIntegrate::inumr: The integrand \!\(\*SubsuperscriptBox[\(\[Integral]\), \(2.0606558625765237`\ k\), \(\(-1.7407054364004024`\)\ \((1 - 2\ k)\) - \*FractionBox[\(808\ k\), \(99\ \*SqrtBox[\(33\)]\)] - \*FractionBox[\(128\ Log[\*FractionBox[\(k\), \(Plus[<<2>>]\)]]\), \(99\ \*SqrtBox[\(33\)]\)]\)]\(\*FractionBox[SuperscriptBox[\(E\), \(-\*SuperscriptBox[\((<<1>>)\), \(2\)]\)], \(\*SqrtBox[\(\((1 - k)\)\ k\)]\ T\)] \[DifferentialD]T\)\) has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}. >>

During evaluation of In[221]:= NIntegrate::inumr: The integrand \!\(\*SubsuperscriptBox[\(\[Integral]\), \(2.0606558625765237`\ k\), \(\(-1.7407054364004024`\)\ \((1 - 2\ k)\) - \*FractionBox[\(808\ k\), \(99\ \*SqrtBox[\(33\)]\)] - \*FractionBox[\(128\ Log[\*FractionBox[\(k\), \(Plus[<<2>>]\)]]\), \(99\ \*SqrtBox[\(33\)]\)]\)]\(\*FractionBox[SuperscriptBox[\(E\), \(-\*SuperscriptBox[\((<<1>>)\), \(2\)]\)], \(\*SqrtBox[\(\((1 - k)\)\ k\)]\ T\)] \[DifferentialD]T\)\) has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}. >>

During evaluation of In[221]:= NIntegrate::nlim: T = 2.06066 k is not a valid limit of integration. >>

During evaluation of In[221]:= NIntegrate::nlim: T = 2.06066 k is not a valid limit of integration. >>

During evaluation of In[221]:= NIntegrate::nlim: T = 2.06066 k is not a valid limit of integration. >>

During evaluation of In[221]:= General::stop: Further output of NIntegrate::nlim will be suppressed during this calculation. >>

During evaluation of In[221]:= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>

During evaluation of In[221]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in k near {k} = {0.977018969826617}. NIntegrate obtained 3.209851121191303` and 3.2931163356283615` for the integral and error estimates. >>

Out[221]= $Aborted

Could somebody point me out the right direction or suggest a hint? Any help is appreciated.

POSTED BY: Adam Domjan
8 Replies
Posted 9 years ago

Your plots are helpful in understanding your function.

I get the same errors, but was not able to get any of the plots.

I agree that the failures in NIntegrate are probably because of the extreme behavior of your function.

Would it be possible to eliminate the points in your function which generate 1/0? Does NIntegrate do better if you can do that?

POSTED BY: Bill Simpson
Posted 9 years ago

I tried the following piece of code:

Clear["Global`*"]
$MaxExtraPrecision = 200;
cons1 = -1/Sqrt[33];
cons2 = 808/(99*Sqrt[33]);
cons3 = 128/(99*Sqrt[33]);
cons4 = 2/Sqrt[33];
cons5 = 1/3;
\[Gamma][x_, k_] := cons1*(1 - 2*k)*x + cons2*k + cons3*Log[k/(1 - k)];
\[Beta][x_, k_] := (cons4*x + cons2)*k;
G1[t_] := Exp[-(t)^2]; (*Gauss function*)
p1 = Table[{Plot3D[
    G1[-\[Gamma][n, k] - T]/(T*Sqrt[k*(1 - k)]), {k, 10^(-10), 
     1 - 10^(-10)}, {T, -\[Beta][n, k], -\[Gamma][n, k]}, 
    AxesLabel -> Automatic, ViewPoint -> {Pi, Pi/2, 2}]}, {n, -7, 8}]
Export["exportP1.png", p1]

And I got the next plots, with the error message: infinite expression 1/0 encountered enter image description here

Are the NIntegrate fails because of the presence of "precipice/deep" in the plots?

POSTED BY: Adam Domjan
Posted 9 years ago

I apologize, I was not clear. When I suggested to see a Plot3D of the "integrand" I did not mean a plot of the result of the integration, but instead a plot of the function you were trying to integrate. I had hoped that by clearly seeing

Plot3D[G1[-\[Gamma][x, k]-T]/(T*Sqrt[k*(1-k)]), {k,0,1}, {T,-\[Beta][x,k], -\[Gamma][x,k]}]

for an assortment of different values of x, including plots of x==0 and x==1, this might show why the result of integrating that seems so difficult.

I agree with you, I do not trust the result from Integrate and I do not know why yet

POSTED BY: Bill Simpson
Posted 9 years ago

Would you perhaps be able to...

Unfortunately not.

I tried to visualize the result with the first derivative of gauss shape function. The integration of

G2[t_] := cons5^2/(t^2 + cons5^2); (*Gauss shape function*)
D[G2[t], {t, 1}];
G3[t_] := -2*c5^2*t/(t^2 + c5^2); (*First derivative of Gauss shape function*)
FullSimplify[Integrate[G3[c6 - T]/T, T]]

have a closed solution according to Wolfram

(c5^2 (-2 c5 ArcTan[(c6 - T)/c5] + c6 (Log[c5^2 + (c6 - T)^2] - 2 Log[-T])))/(c5^2 + c6^2).

Then I retyped the following

Clear["Global`*"]
$MaxExtraPrecision = 100;
cons1 = -1/Sqrt[33];
cons2 = 808/(99*Sqrt[33]);
cons3 = 128/(99*Sqrt[33]);
cons4 = 2/Sqrt[33];
cons5 = 1/3;
\[Gamma][x_, k_] := cons1*(1 - 2*k)*x + cons2*k + cons3*Log[k/(1 - k)];
\[Beta][x_, k_] := (cons4*x + cons2)*k;
G1[t_] := Exp[-(t)^2]; (*Gauss function*)
G2[t_] := cons5^2/(t^2 + cons5^2); (*Gauss shape function*)
G3[t_] := -2*cons5^2*t/(t^2 + cons5^2); (*First derivative of Gauss shape function*)
ListPlot[Table[{x, NIntegrate[G3[-\[Gamma][x, k] - T]/(T*Sqrt[k*(1 - k)]), {k, 0, 1}, {T, -\[Beta][x, k], -\[Gamma][x, k]}]}, {x, -20, 20, 1/100}], Joined -> True]

and I got the a lot of error messages and this plot: enter image description here

Maybe some "trend" can be see, but I still do not trust this.

POSTED BY: Adam Domjan
Posted 9 years ago

Would you perhaps be able to do a Plot3D of your integrand over the range {k,0,1}, and {T,-[Beta][x,k], -[Gamma][x,k]} and do that for a range of x values between 0 and 1? I've repeatedly tried to do that and just get warnings about denominators being zero.

Perhaps if you could clearly show what that integrand looks like then it might be possible to understand why it seems so difficult to integrate.

POSTED BY: Bill Simpson
Posted 9 years ago

Thank you very much your remarks.

Mathematica doesn't seem to find a closed form solution for that.

Maybe I will try with another G1[] functions, because in my result this could be anything. Maybe I will get a closed solution when I integrating first.

I'm not sure if this is integrate-able... Yes, you are absolutely right. That is why I ran a quick test for the integrand.

Clear["Global`*"]
cons1 = -1/Sqrt[33];
cons2 = 808/(99*Sqrt[33]);
cons3 = 128/(99*Sqrt[33]);
cons4 = 2/Sqrt[33];
\[Gamma][x_, k_] := cons1*(1 - 2*k)*x + cons2*k + cons3*Log[k/(1 - k)];
\[Beta][x_, k_] := (cons4*x + cons2)*k;
G1[t_] := Exp[-(t)^2];
Limit[G1[1 - \[Gamma][1, k] - (10)]/(10*Sqrt[k*(1 - k)]), k -> 0, 
 Direction -> 1]
Limit[G1[1 - \[Gamma][1, k] - (10)]/(10*Sqrt[k*(1 - k)]), k -> 0, 
 Direction -> -1]
Limit[G1[1 - \[Gamma][1, k] - (10)]/(10*Sqrt[k*(1 - k)]), k -> 1, 
 Direction -> 1]
Limit[G1[1 - \[Gamma][1, k] - (10)]/(10*Sqrt[k*(1 - k)]), k -> 1, 
 Direction -> -1]

The integrand goes to zero, when k goes to 0 and 1. It seems to be for me, that integrand do not goes to infinity in the integration domain. Nonetheless, when we take integration we get a numerous errors... I wonder how can be circumvents the problem.

POSTED BY: Adam Domjan

I'm not sure if this is integrateable; the function

Plot[1/Sqrt[k*(1 - k)], {k, 0, 1}]

goes to infinity at k=0 and k=1.

And for say (x=0.2) also your function gamma goes to + and - infinity:

Plot[\[Gamma][0.2, k], {k, 0, 1}]
POSTED BY: Sander Huisman
Posted 9 years ago

If you try to simplify your problem down to the essential core, it appears your first question is

Integrate[E^-(c1 - T)^2/T, T]

and Mathematica doesn't seem to find a closed form solution for that.

Giving it hints about the domain of c1 or T or the values of your other symbols, nothing seems to change that.

Trying to use NIntegrate gives a variety of other warnings

Clear["Global`*"]
cons1 = -1/Sqrt[33];
cons2 = 808/(99*Sqrt[33]);
cons3 = 128/(99*Sqrt[33]);
cons4 = 2/Sqrt[33];
\[Gamma][x_, k_] := cons1*(1 - 2*k)*x + cons2*k + cons3*Log[k/(1 - k)];
\[Beta][x_, k_] := (cons4*x + cons2)*k;
G1[t_] := Exp[-(t)^2];
ListPlot[
  Table[{x, NIntegrate[G1[-\[Gamma][x, k]-T]/(T*Sqrt[k*(1-k)]), {k,0,1}, {T,-\[Beta][x,k], -\[Gamma][x,k]}]}, {x,0,1,1/100}], 
 Joined -> True]

which warns

NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 18 recursive bisections in T near {k,T} = {0.124391,0.395515}. NIntegrate obtained 1.0630592251493085` and 2.2018738010911623` for the integral and error estimates. >>

NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 18 recursive bisections in k near {k,T} = {0.0524098,0.11493}. NIntegrate obtained 1.239769698679348` and 2.415984088447202` for the integral and error estimates. >>

NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>

General::stop: Further output of NIntegrate::slwcon will be suppressed during this calculation. >>

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 18 recursive bisections in k near {k,T} = {0.137615,0.472352}. NIntegrate obtained 1.004378071863953` and 2.4738676724088737` for the integral and error estimates. >>

General::stop: Further output of NIntegrate::ncvb will be suppressed during this calculation. >>

and finally displays

enter image description here

But with all the warnings I wouldn't trust that too much

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