Creating a Linear System with a Double Loop

1 vue (au cours des 30 derniers jours)
Hollis Williams
Hollis Williams le 10 Mar 2019
Commenté : Hollis Williams le 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 commentaires
darova
darova le 13 Mar 2019
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
Hollis Williams
Hollis Williams le 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by