Plotting and Integrating difficult functions/Maple or mathematica

In summary, the computer takes a long time to add an integral sign to an expression, and Maple or Mathematica is better than using my laptop because they offer faster calculation times. However, if you don't need a closed form result, Mathematica can take a long time to solve the integral.
  • #1
LBloom
172
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
  • #2
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.
 
  • #3
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.
 
  • #4
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.
 
  • #5
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.
 
  • #6
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.
 
  • #7
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}]
 
  • #8
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.
 

1. What is the difference between plotting and integrating a function?

Plotting a function involves graphically representing the relationship between the independent and dependent variables of a function. Integrating a function involves finding the area under the curve of the function. While plotting helps visualize the behavior of a function, integrating helps calculate its overall effect.

2. What are difficult functions?

Difficult functions are those that cannot be easily expressed in terms of elementary functions (such as polynomials, trigonometric functions, etc.). These functions may involve complicated expressions, special functions, or infinite series.

3. How do I plot a difficult function using Maple or Mathematica?

To plot a difficult function using Maple or Mathematica, you first need to define the function using the appropriate syntax. Then, use the plot function to generate a graph of the function. You can also specify the range of the independent variable and adjust other settings to customize the plot.

4. How do I integrate a difficult function using Maple or Mathematica?

To integrate a difficult function using Maple or Mathematica, you can use the integrate function and specify the function and the limits of integration. If the integration cannot be computed analytically, you can use numerical methods such as the Simpson's rule or the trapezoidal rule to approximate the integral.

5. Can Maple or Mathematica handle all types of difficult functions?

No, Maple and Mathematica have their limits in handling difficult functions. While they have powerful built-in functions for handling a wide range of functions, there may be some functions that are too complex for these software to handle. In such cases, it is recommended to seek other methods or consult with a specialist in the field.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
834
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top