Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.7K Views
|
9 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Getting closed solution from Integrate or speeding up NIntegrate

I have a relatively complicated equation that needs to be integrated. Ideally I would like a closed-form solution, because I will use the solution over and over. How long should I wait for Mathematica (now Wolfram 14.1 for Mac) to "think" before I give it up as having no closed-form solution?

I have used NIntegrate, and it works, but it takes several hours to produce the 3D plot I need, and I need many of them. I have already taken as many approximations as I can afford; with the equation I have now, I will still be off by up to 1%, and I can't afford to be off by more.

I've never let Integrate run for 48 hours before, but I keep hoping it will come up with a solution.

Thanks, everyone who is interested! This is a simple laser propagation through a square aperture, but because I need to predict the output very close to the aperture I can't use the Fresnel approximation (it would be wrong by up to 30%). I'm using the full Huygens-Fresnel model but, since I am looking at a laser, the input is a plane wave.

POSTED BY: Russell Kurtz
9 Replies
Posted 1 year ago

What range of parameters {x,y,z,w,lambda} are ?

Can you give a code to reproduce a 3D plot ?

POSTED BY: Updating Name

I'm trying to determine a general equation if possible. However, if we were to look at the actual value ranges, w will be between 100 and 250, x and y will be between -5w and +5w, z will be between w and 5000, and lambda will be between 0.5 and 1.5.

To make a 3D plot, first I would assign values to w, z, and lambda, something like

ts[x_,y_]:=testSquare/.{w->200,z->1000,lambda->1}

then plot as

Plot3D[ts[x,y],{x,-150,150},{y,-150,150}]

The integration over xi and nu would result in an equation in just x, y, z, w, and lambda. I did this using the second-order approximation and got accurate results for conditions that met the Fresnel diffraction requirements; here I'm looking for something where the second-order approximation results in errors exceeding 10%.

POSTED BY: Russell Kurtz

Regards M.I.

POSTED BY: Mariusz Iwaniuk

Change in the code to better resolution and better grid resolution:

   R = 2;(* If R parameter greater -grid resolution better,but the calculations take longer*)
   data0 = Outer[W0, Subdivide[-X, X, R*X], Subdivide[-Y, Y, R*Y]]; // AbsoluteTiming // First

The code is not mine, so for more information about it, please contact the creator Henrik Schumacher

POSTED BY: Mariusz Iwaniuk
POSTED BY: Michael Rogers

Wow, I'm learning so much about speeding up plotting here...This version took 16.8 seconds to run on my computer, the previous best was nearly 150 seconds and my original was almost 400 seconds. At 16.8 seconds it isn't worth it any more to try to find a closed-form solution.

Thanks!

POSTED BY: Russell Kurtz

FWIW, this returns unevaluated fairly quickly:

idx=0;
Integrate[insideParams4/.\[Eta]->y+\[Eta]/.Power[E,p_]:>E^Collect[foo=p,\[Eta],K[++idx]&],\[Eta]]

I've replaced the coefficients of η with generic parameters K[1], K[2],... and translated the integral η -> y + η. The relatively quick response indicates that Mathematica knows it cannot do this integral. However, it is not a definitive proof it cannot do your original integral. Your original integral might be a special case. But if there is no reason to think so, it probably is not.

If you want to continue trying to find an analytic integral, I'd suggest adding assumptions. For instance, I would guess that most or all of the variables and parameters are real. Integrate[] by default assumes they are complex.

POSTED BY: Michael Rogers

Thanks for the ideas. I am trying Assumptions; in the worst case I can try with numerical values for some of the variables. I did once take an integral that was solved after over 70,000 seconds (per AbsoluteTiming). It was also a little strange that the first time I ran this integration it gave me an error after 1716 seconds -- and the error was that I hadn't defined insideParams4.

I have found that making a table of values using ParallelTable, where I evaluated NIntegrate at 10,000 points, and it took significantly longer than using Plot3D. I haven't tried using Parallelize[NIntegrate]] because I have had many problems with that combination in the past.

The original integral has, for example, sqrt((xi-x)^2+(eta-y)^2+z^2). If I use a second-order approximation I get a closed-form solution but the integrand has errors of 10%. I might be able to accept 1%, which is why I'm trying this fourth-order approximation. I'm trying for a closed-form solution because calculating one for second order took about 1% as long as Plot3D on NIntegrate, and I was able to use Plot3D on a closed-form equation. But, as I said, second-order is not sufficient for this problem.

One thing I could also try is to compare the numerical integration time of the fourth-order approximation to that of the full equation using square roots. My instinct is that the square root would be equally fast or even faster, since the fourth-order version has three times as many variables.

Since I'm not a mathematician, I don't know much more than run this in Mathematica and see what happens. There are two standard approaches to this specific type of problem. One is the second-order approximation, which is insufficient for what I was trying to do; the other is limited to a size about 1/1000 of the area I need.

POSTED BY: Russell Kurtz
Posted 1 year ago

A 3D plot can do tens of thousands, or many more, points and if each of those points requires a very slow calculation then that might partly explain why the plot is so slow.

If your function is sufficiently well behaved and the computer has some free time for an experiment, then you might try using Table to create a matrix of the values of your integral at specific points, using lots fewer points than your plot would otherwise default to. and do a ListPlot3D of that matrix. Experiment to see if you can find the number of points that will show the information you need to see and be faster than what you have now.

POSTED BY: Bill Nelson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard