1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Expanding Mathematica code from 2 dimensions

  1. Jul 21, 2011 #1
    I have this mathematica code to solve a variation of the 2 Dimensional Poisson's equation using the finite difference method.

    xo = .5; yo = .5; \[Sigma] = .05; q = 1;
    Gen[x_, y_] := -q*E^-((((x - xo)^2) + ((y - yo)^2))/(2*\[Sigma]^2));

    GridNum = 300; Hstep = N[1/(GridNum + 1)];
    GridPts = Table[u[i, j], {i, GridNum}, {j, GridNum}];

    FDeqn = {{0, 1, 0}, {1, -4, 1}, {0, 1, 0}}/Hstep^2;
    MatFD = ListCorrelate[FDeqn, GridPts, {2, 2}, 0];
    Short[HE2 =
    Thread[Map[Flatten,
    MatFD ==
    Table[Gen[Hstep i, Hstep j], {i, GridNum}, {j, GridNum}]]], 10];

    {row, col} = CoefficientArrays[HE2, Flatten[GridPts]];

    sol2D = LinearSolve[col, row];
    sol2D = Partition[sol2D, GridNum];
    sol3D = LinearSolve[col, -row];
    sol3D = Partition[sol3D, GridNum];


    I would like some assistance in using this same exact method to solve the problem for the 1 dimensional and 3 dimensional case.

    I tried to just delete each part dealing with one dimension (to do the one dimensional case) such that everything that had to deal with x and y just dealt with x. The Table was a 300x1 table etc. I tried to add in a dimension in the same fashion, but kept getting errors when I tried to do the ListCorrelate step saying that the kernel and the table didn't have the same tensor rank. Thank you in advance.
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?



Similar Discussions: Expanding Mathematica code from 2 dimensions
  1. Sic matlab code (Replies: 0)

  2. ADSL Matlab code (Replies: 0)

  3. Mathematica Hw (Replies: 0)

  4. Mathematica plot (Replies: 0)

Loading...