@355073677
2016-05-21T11:52:23.000000Z
字数 3984
阅读 1374
计算物理
Name:陈锋
Student Number: 2013301020145
May 21, 2016
This article made a comparsion between Jacobi method and SOR algorithm to solve partial differential equation. Also, it compared the number of iterations and figured out the relation between the number of iterations and the number of grid elements.
As we known, the electric potential satisfies Laplace's equation in the space without any electric charges.
If we only use the old potential to calculate the new one, the formula becomes:
Obviously, we can make use of the new values as they become available, which means:
Firstly, I set a crawler to get the initial value and boundary conditions which have been set in a .txt file.
Figure 1: This is the initial value and boundary conditions in the case of FIGURE 5.6 of textbook. The potential of boundaries is zero. In the inner space, there are two capacitor plates held at (left plate) and (right plate).
Here is the core code:
def initialization(self,initial_file):
itxt= open(initial_file)
self.lattice_in = []
self.lattice_out = []
for lines in itxt.readlines():
lines=lines.replace("\n","").split(",")
self.lattice_in.append(lines[0].split(" "))
self.lattice_out.append(lines[0].split(" "))
itxt.close()
for i in range(len(self.lattice_in)):
for j in range(len(self.lattice_in[i])):
self.lattice_in[i][j] = float(self.lattice_in[i][j])
self.lattice_out[i][j] = float(self.lattice_out[i][j])
return 0
Use both of these method, we can easily solve the problem of the potential near two capacitor plates.
Figure 2: Solving the problem in the 11*11 grids.
Figure 3: Enlarging the grids to 26*26 leads to smoother equipotential curve and a finer structure of electric field.
In this section, I will make a discussion on the relationship between the number of iterarions and that of grid elements. For convenience, all the grids I used to solve equation is square grids.
Figure 4: The fitting results are for the blue curve and for the red one, which means the number of iteration is proportional to for jacobi method and is proportional to for SOR algorithm.
Therefore, the larger grid we used, the bigger advantage of SOR algorithm would be showed.
On the other hand, we can make a comparison of the convergence speed of these methods.
Figure 5: The convergence speed of SOR algorithm is much larger than that of jacobi method.
Additionally, I make a discussion of the relation between the number of iteration and the value of .
Figure 6: In this case, I set the length of grid is 26, which means the value of is about 1.784. Obviously, this is not the best choice to decrease the number of iterations.
1.Giodano, N.J., Nakanishi, H. Computational Physics. Tsinghua University Press, December 2007.
2.Matplotlib Gallery, http://matplotlib.org/gallery.html