How Can I Fix My Mathematica Animation Code for Propagator Integration?

In summary, the NIntegrate is blowing up and will likely never finish, and the code is trying to perform an integrand across the domain that is too ill conditioned.
  • #1
axelalma
3
0
Hello!

I need some help in Mathematica, because I'm newbie in using this program.

I've a kernel for a propagator, what i want to integrate numerically by p (because the problem hasn't got analitical solution) to receive the propagator. Next i want to use that propagator for an initial state and i want to plot the square of the absolute value of the obtained wavefunction around the pole, so that the time (in my code this is t1) will run over an interval, so it would be a running animation.

My code is here, where psi0[x] is the initial state, k1[x,x1,t,t1,p] is the kernel of the propagator and t1 runs over the interval {0,10}:

Animate[Plot[Abs[NIntegrate[psi0[x1]*k1[x, x1, 0, t1, p], {x1, -Infinity, Infinity}, {p, 0, Infinity}, MaxRecursion -> 10]]^2, {x, -1, 1}, PlotPoints -> 10, MaxRecursion -> 10], {t1, 0, 10}, AnimationRunning -> False]

It isn't working, that's why i need help.

Sorry, my language skills are low.:frown:
Thank you in anticipation
 
Physics news on Phys.org
  • #2
Can you give the definitions of psi and k1?
 
  • #3
Hepth said:
Can you give the definitions of psi and k1?

I send you the nb file where you can find both, because the k1 is too difficult to write in a message.View attachment blabla.nb
 
  • #4
Discard the animation and see if it is possible to get a single plot.

In[19]:= t1 = 2; Plot[Abs[NIntegrate[psi0[x1]*k1[x, x1, 0, t1, p], {x1, -Infinity, Infinity}, {p, 0, Infinity}, MaxRecursion -> 10]]^2, {x, -1, 1}, PlotPoints -> 10, MaxRecursion -> 10]

During evaluation of In[19]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 20 recursive bisections in p near {x1,p} = {0.,9.53674*10^-6}. NIntegrate obtained 2.1491*10^83+3.71159*10^83 I and 4.172240692690985`*^83 for the integral and error estimates. >>

Out[19]= $Aborted

so the NIntegrate is blowing up and will likely never finish.

Can you see a way to get the code to provide a numeric integral across the domain?
 
  • #5
Bill Simpson said:
Discard the animation and see if it is possible to get a single plot.

In[19]:= t1 = 2; Plot[Abs[NIntegrate[psi0[x1]*k1[x, x1, 0, t1, p], {x1, -Infinity, Infinity}, {p, 0, Infinity}, MaxRecursion -> 10]]^2, {x, -1, 1}, PlotPoints -> 10, MaxRecursion -> 10]

During evaluation of In[19]:= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 20 recursive bisections in p near {x1,p} = {0.,9.53674*10^-6}. NIntegrate obtained 2.1491*10^83+3.71159*10^83 I and 4.172240692690985`*^83 for the integral and error estimates. >>

Out[19]= $Aborted

so the NIntegrate is blowing up and will likely never finish.

Can you see a way to get the code to provide a numeric integral across the domain?

I can't
 
  • #6
In your blabla.nb notebook there is one typo I found

k2[x_, x1_, t_, t1_, p_] := Piecewise[{{k[x, x1, t, t1, p]*...^(-1), 0 > x 1}}]

notice there is a space between x and 1 in your last 0>x 1.

Mathematica is going to interpret that as 0>x*1 which is 0>x.

That is the only thing that looks like an obvious error that I've found thus far.

I've looked at using FullSimplify on your A[], A1[] and A2[] in an attempt to make the final result much simpler and made some progress, but not enough yet. What I really want to see is if there is some way to make your k[] substantially simpler, perhaps see if your final integral might be broken into pieces where each piece is well behaved and see if there is some way to get a well behaved result despite the ill conditioned coefficients. I looked to see if I could find an alternative to your Piecewise[] in your k2[] and k3[] but not had any success yet.
 
  • #7
If I haven't broken something with these changes,

k2[x_, x1_, t_, t1_, p_] := k[x, x1, t, t1, p]*(p - A[t]*e/c)^(-Sign[x1])*(I*d + Sqrt[(p - A[t]*e/c)^2 - d^2]);
k3[x_, x1_, t_, t1_, p_] := k[x, x1, t, t1, p]*(p - A[t1]*e/c)^(Sign[x])*(I*d + Sqrt[(p - A[t1]*e/c)^2 - d^2]^(-Sign[x]));

And then I try a limited plot with this,

t1 = 0;
ListPlot[Table[Abs[NIntegrate[ psi0[x1]*k1[x, x1, 0, t1, p], {x1, -10, 10}, {p, 0, 10}, MaxRecursion -> 10]]^2, {x, -1, 1, 1/5}], Joined -> True]

then I do get a plot after a couple of minutes. If I change the value of t1 and repeat then I get another similar plot after a couple of minutes.

But, as you can see from the scale on the vertical axis, I suspect the plot isn't really telling you what you want to know.

If I clear the value of t1 and put that ListPlot inside your Animate[] then I get $Aborted[] instead of the ListPlot after a couple of minutes. I haven't been able to track down why that happens.

EDIT: Ah, found this:
http://reference.wolfram.com/mathematica/tutorial/AdvancedManipulateFunctionality.html
which says down about 1/4 of the way
"And beyond five seconds you will start seeing $Aborted instead of the number, because the system is protecting itself from unreasonably long evaluations, which block other activity in the front end in this situation"
so that may explain the failure of Animate to show the plot. That web page says that adding the option ContinuousAction->False to the Animate will allow arbitrarily long evaluations, but when I try this I still get the $Aborted[] instead of your plot.
 
Last edited:
  • Like
Likes 1 person

1. How can I make an animation using Mathematica?

To make an animation in Mathematica, you can use the built-in Manipulate function. This function allows you to manipulate variables and see the changes in real time. By using Animate, you can create a sequence of frames that will be displayed as an animation.

2. How can I control the speed and duration of my animation?

You can control the speed and duration of your animation by adjusting the parameters in the Animate function. The AnimationRate option allows you to specify the number of frames to display per second, while the AnimationRepetitions option allows you to specify the number of times the animation should repeat. You can also use the Manipulate function to manually control the variables that affect the speed and duration of your animation.

3. Can I export my animation to a video file?

Yes, you can export your animation to a video file using the Export function in Mathematica. You will need to specify the file format (such as .avi or .mp4) and the name of the file. You can also use the CloudExport function to save your animation to the Wolfram Cloud.

4. Is it possible to add text or labels to my animation?

Yes, you can add text or labels to your animation using the Epilog option in the Animate function. This allows you to add additional graphics to your animation, including text and labels. You can also use the Text and Callout functions to add text or labels to specific frames in your animation.

5. Can I include 3D graphics in my animation?

Yes, you can include 3D graphics in your animation by using the Graphics3D function. This allows you to create and manipulate 3D objects, such as cubes or spheres, and incorporate them into your animation. You can also use the Show function to combine multiple 3D graphics into one animation.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
228
  • MATLAB, Maple, Mathematica, LaTeX
Replies
34
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
891
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top