MATLAB Answers

0

Creating a Linear System with a Double Loop

Asked by Hollis Williams on 10 Mar 2019
Latest activity Commented on by 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.

  4 Comments

Show 1 older comment
I've added a picture, let me know if you need any further explanation or diagrams as I feel like there must be a way of doing this as the brute force approach I was taking doesn't always work.
So in the diagram you see there is a smaller blue inner sphere inside a larger black unit sphere. If there are 4 nodes on the outer sphere, there are 4 corresponding nodes on the inner sphere. In the second part, you see there is a distance from the outer node to the 4 inner nodes. You have a function which takes as input the distance from the outer node to one of the inner nodes, so you evaluate that function 4 times for the distance to each inner node and sum the contribution for the distance to each inner node. That gives a scalar A which goes into the matrix.
In part 3, you see there are another 8 functions which you evaluate one after another for the same node in the same way. Basically, all the 9 functions are just getting you the Cartesian components for a normal and two tangential vectors, but it doesn't matter.
Then in part 4, you see that I go to the next outer node and do exactly the same to add another block to the matrix, so however many N nodes you have, you end up with a matrix corresponding to 3N equations in a system which I can solve with boundary conditions I already know.
DSC_0993.jpg
Capture.PNG A those circles have one center or they have eccentric?
If you have radial distance, how do you know which vector is that? Do you have dimension those spheres?
r = 5;
d = 2;
a = linspace(0,pi,100);
D = sqrt( r*r+(r+d)^2-2*r*(r+d)*cos(a) );
plot(a,D)
m = mean(D);
s = trapz(a,D)/(a(end)-a(1)); % dividing by pi
m/s*100
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.

Sign in to comment.

Products

0 Answers