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

In summary, the code written on a computer at school produces strange results. The ListPlot3D works fine, but the ArrayPlot produces a bell noise and all saved variables turn blue.
  • #1
swooshfactory
63
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
  • #2
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?
 

1. Why won't my Mathematica array plot work?

There could be several reasons why your array plot is not working. Some common issues include incorrect syntax, missing or incorrect plot options, or incompatible data types. Double-check your code and make sure you are using the correct functions and options for your specific plot. If the issue persists, try restarting Mathematica or updating your software.

2. Why does my Mathematica array plot erase all of my stored variables?

This can happen if you are using the "Clear" function before plotting your array. This function clears all variables and definitions in the current session. To avoid this, make sure you are not using "Clear" before plotting and use "ClearAll" instead, which only clears specific variables.

3. How can I store my variables before plotting an array?

You can use the "Save" function to save your variables in a separate file before plotting your array. This way, you can access and use them again later without losing them during the plotting process. Alternatively, you can also use the "Hold" function to temporarily store your variables without evaluating them.

4. Why is my array plot not showing any data or labels?

If your array plot is not showing any data or labels, make sure you have provided the correct data and options for your plot. Check the dimensions of your array and make sure they match the expected input for the plot. Also, check if you have specified the correct labels and options for labeling your plot.

5. Can I customize the appearance of my Mathematica array plot?

Yes, you can customize the appearance of your array plot by using various options and functions. You can change the color scheme, add labels and titles, adjust the plot size, and more. Consult the Mathematica documentation for a full list of available options and functions for customizing your array plot.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
11
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • Introductory Physics Homework Help
Replies
8
Views
499
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
Back
Top