# Creating a Linear System with a Double Loop

1 view (last 30 days)
Hollis Williams on 10 Mar 2019
Commented: Hollis Williams on 13 Mar 2019
I am dealing with a system where I have one sphere inside of a larger one and I work with the radial vector for the distance between the outer shell and the inner shell. I have nodes spaced equally around the outer shell and there is the same number of nodes corresponding to the outer nodes with exactly the same spacings on the inner shell.
For a outer node, I have to evaluate a function which produces a scalar which goes into the first element of a matrix as A. The function has as its input the magnitude of the radial vector for the distance from the outer node to one of the inner nodes, and I then have to sum the contributions when I evaluate the function inputting the distance from the outer node to each of the inner nodes (so if I chose 10 nodes on the outer shell, that's 10 terms for the 1 outer node and the distance from it to the 10 corresponding inner nodes). Then, there is a second function (also just depending on the distance from the outer to the inner node) to get the element B, and another to get element C for the first row of the matrix (really the same function every time but for the Cartesian components of a force vector). A further 6 functions at the outer node give us the next two rows of the matrix, so we end up with a system of 3 linear equations when combined with the boundary conditions.
The aim is then to repeat this for every outer node to create a system of 3N equations. I think there is a brute force way of doing this where you loop over all the outer nodes, and then loop over each inner node for every outer node, but I was wondering if there is a more efficient way of doing this and building the matrix, as it seems like trial and error to somehow get the dimensions of everything to line up correctly. I can explain in more detail if necessary or post bits of the code if that helps, if anyone can help I would appreciate it as I am getting into a mess with this.
Hollis Williams on 13 Mar 2019
The circles all have one centre, it's a smaller sphere with radius 0.2 inside a sphere with radius 1. For the radial distance, if you imagine the vector from the origin to the outer node and the vector from the origin to the inner node, I need the distance between them so it's position vector for the outer node minus position vector for the inner node.
Then I need that contribution for each of the inner nodes when I choose one outer node, let me know if I can explain further.