Mathematica Mathematica array plot won't plot and it erases all of my stored variables

AI Thread Summary
The discussion revolves around a coding issue encountered while running a Mathematica script on a Toshiba Satellite computer. The script involves complex numerical integration to generate two-dimensional arrays, specifically using NIntegrate for calculations related to Ediff and Idiff1. The user reports that while ListPlot3D executes without issues, the ArrayPlot causes the computer to malfunction, resulting in a bell noise and loss of saved variables. Participants suggest that there might be syntax errors, particularly missing brackets in the code, and recommend testing with a reduced dimension to troubleshoot performance issues. Warnings about NIntegrate indicate potential problems with convergence due to insufficient precision or oscillatory integrals, leading to arrays filled with approximate numbers. The discussion emphasizes the need for code refinement to eliminate uncertainties for successful execution of all plotting functions.
swooshfactory
Messages
61
Reaction score
0
Hi, I wrote some code on a computer at school.

dim = 50;
Ediff = ConstantArray[0, {dim, dim}];
\[Lambda] = .5; steps = 10;

Ediff = ConstantArray[0, {dim, dim}];
L = 1;
For[xs = 1, xs <= dim, xs++,
For[ys = 1, ys <= dim, ys++,
Ediff[[xs, ys]] =
Ediff[[xs, ys]] +
NIntegrate[
Sqrt[(xa - xs)^2 + (ya - ys)^2]/((xa - xs)^2 + (ya - ys)^2 +
L^2) Exp[
I 2 \[Pi] / \[Lambda] Sqrt[(xa - xs)^2 + (ya - ys)^2 +
L^2]], {xa, dim/2 - steps, dim/2 + steps}, {ya, dim/2 - 1,
dim/2 + 1}, AccuracyGoal -> 2] +
NIntegrate[
Sqrt[(xa - xs)^2 + (ya - ys)^2]/((xa - xs)^2 + (ya - ys)^2 +
L^2) Exp[
I 2 \[Pi] / \[Lambda] Sqrt[(xa - xs)^2 + (ya - ys)^2 +
L^2]], {xa, dim/2 - 1.5, dim/2 + 1.5}, {ya, dim/2 - steps,
dim/2 - 1}, AccuracyGoal -> 2] +
NIntegrate[
Sqrt[(xa - xs)^2 + (ya - ys)^2]/((xa - xs)^2 + (ya - ys)^2 +
L^2) Exp[
I 2 \[Pi] / \[Lambda] Sqrt[(xa - xs)^2 + (ya - ys)^2 +
L^2]], {xa, dim/2 - 1.5, dim/2 + 1.5}, {ya, dim/2 + 1,
dim/2 + steps}, AccuracyGoal -> 2]

Idiff1 = ConstantArray[0, {dim, dim}];

For[xs = 1, xs <= dim, xs++,
For[ys = 1, ys <= dim, ys++,
Idiff1[[xs, ys]] = Ediff[[xs, ys]]*Conjugate[Ediff[[xs, ys]]]]]

ListPlot3D[Idiff1, PlotRange -> {0, .002}]

ArrayPlot[Idiff1]




My Toshiba Satellite computer will run all but the array plot. It gives a bell noise and then all saved variables go blue. The ListPlot3D will work, but something is weird about the array plot. Any ideas?
 
Physics news on Phys.org
If I scrape your code off the screen and paste it into Mathematica

You are missing a couple of ] somewhere and I can't guess where those go. I try putting those immediately after your Ediff=Ediff+NIntegrate.

It takes long enough to run your code that I reduce dim to 5 as a test. With that I get warnings about NIntegrate finding your integrals converging too slowly, perhaps because of insufficient precision or oscillatory integrals.

Because you are using .5 and NIntegrate your resulting arrays are filled with approximate numbers. As a result your Ediff*Conjugate[Ediff] is filled with approximatenumber+0.*I

If I ignore all those questionable things then the ListPlot and ArrayPlot finish with no complaints.

Can you edit your code to remove any of those uncertainties and we will try it again?
 

Similar threads

Replies
11
Views
2K
Replies
2
Views
1K
Replies
6
Views
6K
Replies
9
Views
3K
Replies
4
Views
5K
Replies
4
Views
3K
Replies
10
Views
2K
Replies
10
Views
3K
Replies
2
Views
2K
Back
Top