Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. May 30, 2012 #1
    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?
     
  2. jcsd
  3. May 30, 2012 #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?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Mathematica array plot won't plot and it erases all of my stored variables
  1. Mathematica plot (Replies: 1)

  2. Plot in mathematica (Replies: 2)

Loading...