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

Click For Summary
SUMMARY

The discussion centers on issues encountered while plotting arrays in Mathematica, specifically with the ArrayPlot function. The user reports that their Toshiba Satellite computer successfully executes ListPlot3D but fails with ArrayPlot, resulting in the loss of stored variables. The code provided includes multiple NIntegrate calls, which may lead to slow convergence and precision issues, particularly with the parameters set for integration. Suggestions include debugging the code for missing brackets and addressing the precision of the NIntegrate function to improve performance.

PREREQUISITES
  • Familiarity with Mathematica programming and syntax
  • Understanding of numerical integration techniques, specifically NIntegrate
  • Knowledge of array manipulation in Mathematica
  • Basic concepts of complex numbers and their conjugates
NEXT STEPS
  • Debug Mathematica code for syntax errors, focusing on bracket placement
  • Optimize NIntegrate settings for better convergence and precision
  • Explore the use of ListPlot3D and ArrayPlot for visualizing multidimensional data
  • Investigate the impact of variable types and precision on numerical computations in Mathematica
USEFUL FOR

Mathematica users, computational scientists, and anyone involved in numerical analysis or data visualization who seeks to troubleshoot plotting issues and improve code efficiency.

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 ·
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K