I am working on an analytical model for the sound intensity generated from a vibrating cylinder. Part of this work requires me to split the cylinder up into a number of elements, with the more elements increasing the accuracy of my results.
I am fairly new to Mathematica and would like to generate a function that will have the following inputs and output.
Input: Number of vertical partitions (nn), number of circumferential partitions (mm), and Cylinder height (L) and, outer radius (a).
Output: Matrix where each element contains distance between the centroid's of two of the elements.
For example, for a cylinder with height L = 2 m and outer radius a = 1 m and we split the cylinder into 4 elements we would have nn = 1 vertical partition and mm = 2 circumferential partitions. The function would then output a 4 by 4 matrix containing the distance between element 1 and elements 1, 2, 3 and 4, element 2 and elements 1, 2, 3 and 4, etc.
So far I have managed to produce a table containing the coordinates of the centroid of each element. Using,
CentroidList = Table[{tr = a, t\[Theta] = (i*\[Pi])/mm, tz = (j*L)/(2*nn)}, {i,Range[1, 2*mm, 2]}, {j, j = 1, j = 2*nn, j = j + 1}]
Now I am trying to use this Table to generate the matrix which will contain the distance between each of the centroids. What is the best way to do this?
So far I have only been able to produce the distance between two centroids by using the following (where I must manually input the indexes for Part[ ] to get the correct result);
Example, distance between centroid of element 1 and centroid of element 2:
r12 = Sqrt[(Part[CentroidList, 1, 1, 1]*
Cos[Part[CentroidList, 1, 1, 2]] -
Part[CentroidList, 1, 2, 1]*
Cos[Part[CentroidList, 1, 2, 2]])^2 + (Part[CentroidList, 1, 1,
1]*Sin[Part[CentroidList, 1, 1, 2]] -
Part[CentroidList, 1, 2, 1]*
Sin[Part[CentroidList, 1, 2, 2]])^2 + (Part[CentroidList, 1, 1,
3] - Part[CentroidList, 1, 2, 3])^2]
Is is possible to repeat this calculation (automatically changing the indexing in Part[ ]) and assigning the result to a particular location in a matrix?
With[{a = 1, nn = 1, mm = 2, L = 2}, CentroidList = Table[{a, i π/mm, j L/(2 nn)}, {i, 1, 2 mm, 2}, {j, 1, 2 nn}]]; DistanceMatrix[Flatten[Apply[Append[#1 Through[{Cos, Sin}[#2]], #3] &, CentroidList, {2}], 1]]
suit your needs? (A lot of what you were trying to do inTable[]
didn't really need to be done.) $\endgroup$With[{a = 1, nn = 1, mm = 2, L = 2}, CentroidList = Table[{a, i \[Pi]/mm, j L/(2 nn)}, {i, Range[1, 2 mm, 2]}, {j, j = 1, 2 nn, j = j + 1}]]; DistanceMatrix[ Flatten[Apply[Append[#1 Through[{Cos, Sin}[#2]], #3] &, CentroidList, {2}], 1]]
$\endgroup$Table[]
's iterator argument; you can just as easily writeTable[{a, i π/mm, j L/(2 nn)}, {i, 1, 2 mm, 2}, {j, 1, 2 nn}]
. $\endgroup$