[关闭]
@2014301020081 2016-12-11T16:13:15.000000Z 字数 1730 阅读 453

The twelve homework of computational physics of 5.1

孔德锋 2014301020081


摘要

因为我的spyer无法汇出三维图片(无函数包),因此此次作业采用matlab进行操作,汇出figure5.4的V的三维分布图

背景

使用书中介绍的the Jacobi method
对于二维空间使用:


first:initial-V
second:update-V
third:laplace-calculate

正文及结论

利用matlab语言,可分成三步:
1. Laplace_prism
2. Initialise_prism
3. Update_prism

  1. [V] =Initialise_prism;
  2. % run update routine and estimate convergence
  3. [V_new, delta_V_new]=Update_prism(V);
  4. loops=0;
  5. %Initialise loop counter
  6. % While we have not met the convergence criterion and the number of loops is <10 so that we give the relaxation
  7. % algorithm time to converge
  8. while (delta_V_new>4e-5 | loops < 20);
  9. loops=loops+1;
  10. [V_new, delta_V_new]=Update_prism(V_new);
  11. mesh (V_new,'FaceColor','interp');
  12. title('Potential Surface');
  13. axis([0 20 0 20 0 1]);
  14. drawnow;
  15. pause(0.5);
  16. end;
  1. % This function creates the intial voltage array V
  2. function[V] =Initialise_prism;
  3. clear;
  4. V = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  5. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  6. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  7. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  8. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  9. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  10. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  11. 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0
  12. 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0
  13. 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0
  14. 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0
  15. 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0
  16. 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0
  17. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  18. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  19. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  20. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  21. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  22. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  23. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  24. ];
  1. %This function creates the Update_prism array V
  2. function [ V_new, delta_V_new ] = Update_prism(V);
  3. row_size = size(V,1);
  4. column_size=size(V,2);
  5. V_new=V;
  6. delta_V_new=0;
  7. for j =2:column_size-1;
  8. for i=2:row_size -1;
  9. % Do not update V in metal bar
  10. if V(i,j) ~=1;
  11. % If the value of V is not =1, calculate V_new and
  12. % delta_V_new to test for convergence
  13. V_new(i,j) = (V(i-1,j)+V(i+1,j)+V(i,j-1)+V(i,j+1))/4;
  14. delta_V_new=delta_V_new+abs(V_new(i,j)-V(i,j))
  15. else
  16. % otherwise, leave value unchanged
  17. V_new(i,j)=V(i,j);
  18. end;
  19. end;
  20. end;

此处输入图片的描述

感谢

Computational Physics using MATLAB®

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注