Plotting and Integrating difficult functions/Maple or mathematica

Click For Summary

Discussion Overview

The discussion revolves around the challenges of performing numerical simulations for the diffraction of Laguerre-Gaussian beam modes, specifically focusing on the difficulties encountered when using software like Mathematica and Maple for complex integrals. Participants share their experiences and seek advice on how to effectively compute and plot these integrals.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant describes the complexity of integrals related to their research on optics and seeks advice on whether to use Mathematica or Maple for numerical simulations.
  • Another participant suggests that declaring variables as real can significantly speed up computations in Mathematica, as it reduces the search space for the integral solver.
  • Some participants recommend using NIntegrate for numerical integration instead of seeking closed-form solutions, especially when comparing results against experimental data.
  • A participant shares a specific function definition and integral setup related to their work, indicating the parameters and the intended range for integration.
  • There is a suggestion to use Plot3D to visualize the intensity distribution after performing the integration.
  • Participants discuss the importance of defining functions correctly in Mathematica to optimize the performance of NIntegrate, including the use of caching results for efficiency.
  • One participant mentions using ContourPlot in conjunction with NIntegrate but indicates they still need to manipulate the integrand before finalizing their functions.

Areas of Agreement / Disagreement

Participants generally agree on the utility of NIntegrate for numerical integration and the importance of variable declarations in Mathematica to improve performance. However, there is no consensus on the best software to use, as opinions vary between Mathematica and Maple based on personal experience.

Contextual Notes

Some participants note that the complexity of integrals can lead to long computation times, and there are unresolved questions about how to best manipulate the integrands for efficient numerical integration.

LBloom
Messages
169
Reaction score
0
Hi Everybody,

So basically I spent the summer working on some optics related stuff and now they want me to present my research work. This means I'm going to have to do numerical simulations for diffraction of Laguerre-Gaussian beam modes. In a word, the integrals are ridiculously long and complicated if they're integrable. Often my computer will be running a long time just to add an integral sign to my expression.

Anyway the question is: When trying to calculations on a laptop (Macbook Pro, 13", 2.26 ghz processor and 4gb of RAM), which software is better to use: Mathematica or Maple. I'm more acquainted with mathematica but the problem with it is it'll take forever trying to calculate the integral before just putting an integral sign in front of my expression and then trying to plot the absolute value of the function (bc i want the intensity distribution) takes FOREVER. I've never used maple before but I can probably learn the basics quickly.

So Maple or Mathematica or maybe just not use my laptop.

Thanks!
 
Physics news on Phys.org
Do you have an integral for us to try? Usually mathematica takes a long time when the integral is not easily solved in a closed form. BUT computers are dumb, and something as simple as declaring certain variables to be real will sometimes make the integral instant, as the software no longer has to look at all possibilities.

Give me an example, online or otherwise that your mathematica can't solve and I'll see if there's something that I can whip up to help.
 
Do you need a closed form result or is it just to compare against your data?
If it's the latter, you should probably use NIntegrate.

As Hepth, post an example of your integral (along with some reasonable numerical values for any parameters), and someone might be able to give more specific advice.
 
Ok so I defined a function U[x,y,m,l] where m and l are terms in the associated Laguerre polynomial (m being the bottom index, l being the top). I've kept m=0 and I've been varying l.

U[x0,y0,0,3]=(Sqrt[2]*r0/w0)^3*LaguerreL[m, l, 2*r0^2/w0^2]*Exp[-r0^2/w0^2]*
Exp[i*3*theta0]

where r0^2=x^2+y^2 and theta0=ArcTan[x/y]
w0 is the beam waist and is approximately 2.4*10^-4 meters.

So U is the electric field distribution and the entire diffraction integral is (I'm putting my screen 10^4 meters away. That's not an important number, just wanted it in the far field. Probably overshot it):

U1[x0, y0, 4, 0]*I*k/(2*Pi*10^4)*Exp[-I*k*10^4]*
Exp[-I*k/(2*10^4)*((x0^2 + y0^2) - 2 (x*x0 + y*y0) + (x^2 + y^2))]

or

(-7.56023*10^15 - 1.72943*10^17 I) E^(-1.65486*10^7 (x0^2 + y0^2) - (0. +
496.459 I) (x^2 + x0^2 + y^2 + y0^2 - 2 (x x0 + y y0)) +
4 I ArcTan[x0/y0]) (x0^2 + y0^2)^2

What I was trying to do was a double integral over x0 and y0 taking each value from -.0003 to .0003 (that value isn't too important i was also using .0004 &.0005)

I haven't declared my variables as real (not sure how to do that) and I don't want my integral in a closed form, I just want to plot the data and compare to my experimental values. I haven't used NIntegrate before, I'll try that out.
 
Another thing is that I want to plot the results when I'm done because I need to compare my intensity distribution with the theoretical results. I've been using Plot3D so far.
 
Yeah, try using NIntegrate. Basically make a function like:

F[xx_,yy_] := NIntegrate[(...),{x0,-xx,xx},{y,-yy,yy}]

Then Plot3D[F[0.003,0.003],{x,-1,1},{y,-1,1}]

The " := " instead of a " = " means for it to run the function when it is called, rather than before.
 
It's better to use

F[xx_?NumericQ,yy_?NumericQ] := NIntegrate[(...),{x0,-xx,xx},{y,-yy,yy}]

so that NInntegrate won't be called for symbolic arguments.

If the NIntegrate is really expensive and you're going to do lots of plots, it might be worth caching the results:

F[xx_?NumericQ,yy_?NumericQ] := F[xx,yy] = NIntegrate[(...),{x0,-xx,xx},{y,-yy,yy}]
 
Thanks for the advice. I'm using NIntegrate with the ContourPlot function, but I haven't defined any new functions yet because I still need to manipulate what's under the integral sign.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K