Help with Mathematica: 3D Point Definition

  • Context: Mathematica 
  • Thread starter Thread starter dg88
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
SUMMARY

This discussion focuses on defining a set of 3D points in Mathematica for simulating a laser scattering experiment. The user compares their C++ implementation with Mathematica, seeking a method to create multidimensional arrays. The suggested solution involves using an empty matrix and the AppendTo function to add elements iteratively, which allows for dynamic point definition and further calculations.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of multidimensional arrays
  • Basic knowledge of laser scattering experiments
  • Experience with iterative programming constructs
NEXT STEPS
  • Learn how to use AppendTo in Mathematica for dynamic array manipulation
  • Explore the Reap and Sow functions for collecting results in Mathematica
  • Study the creation and manipulation of multidimensional arrays in Mathematica
  • Investigate laser scattering simulation techniques in computational physics
USEFUL FOR

Mathematica users, physicists conducting simulations, and programmers transitioning from C++ to Mathematica for scientific computing.

dg88
Messages
10
Reaction score
0
Hello,

1) I am trying trying to simulate a laser scattering experiment in Mathematica. So the first trouble I have is how to define a set of 3D points. I did this program in C++ like this:
for (int i=0; i<3; i++)
{
pyr[0].point[0]=0;
}
for (int a=1; a<3; a++)
{
for (int b=0; b<3; b++)
{
if (b == 1) // adding sqrt(2) to the Y cordinate
{
pyr[a].point[0]=pyr[a-1].point[0]+ sqrt(2.0);
}
else
{
pyr[a].point[0]=pyr[a-1].point[0];
}
}
}
for (int c=0; c<3;c++)
{
if (c==0)
{
pyr[3].point[0][c]=pyr[0].point[0][c]+ sqrt(2.0);
}
else
{
pyr[3].point[0][c]=pyr[0].point[0][c];
}

}
for(int d=4;d<6; d++)
{
for (int e=0;e<3;e++)
{
if (e == 1) // adding sqrt(2) to the Y cordinate
{
pyr[d].point[0][e]=pyr[d-1].point[0][e]+ sqrt(2.0);
}
else
{
pyr[d].point[0][e]=pyr[d-1].point[0][e];
}
}
}
for (int f=0; f<3;f++)
{
if (f==0)
{
pyr[6].point[0][f]=pyr[3].point[0][f]+ sqrt(2.0);
}
else
{
pyr[6].point[0][f]=pyr[3].point[0][f];
}
}
for(int g=7;g<9; g++)
{
for (int h=0;h<3;h++)
{
if (h == 1) // adding sqrt(2) to the Y cordinate
{
pyr[g].point[0][h]=pyr[g-1].point[0][h]+ sqrt(2.0);
}
else
{
pyr[g].point[0][h]=pyr[g-1].point[0][h];
}
}
}


The question is, how do I define these points in Mathematica? Is there a way I can have multidimensional arrays and define the points like above and then use then for further calculations?

Thanks in advance
dg
 
Physics news on Phys.org
Define an empty matrix then use AppendTo (or Reap and Sow) to add elements in a loop or whatever.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K