Advertisement
fellpz

Exemplo 02: Eq. Laplace c/ condições de Dirichlet e Newmann

Dec 7th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.69 KB | None | 0 0
  1. %IFPB 07/12/2017
  2. %EXEMPLO 2 - EQUAÇÃO DE LAPLACE COM CONDIÇÕES DE DIRICHLET E DE NEWMANN
  3. %LINHA DE MICROFITA SUSPENSA NO AR
  4.  
  5. close all, clear all, clc;
  6. %malha computacional bidimensional
  7. n=100; r=10; V=100;
  8. p=n; q=n; x=1:n; y=x; h=1;
  9. %condições de contorno
  10. u=zeros(p,q);
  11. u(r,50:60)=V,g=0;
  12. %equação de diferenças
  13. for iter=1:1000
  14.     for i=2:p-1
  15.         for j=50:q-1
  16.             if i==r & j>=50 & j<=60,
  17.                 u(r,j)=V;
  18.             elseif i~=r & j==50,
  19.                 u(i,j)=0.25*(u(i+1,j)+u(i-1,j)+2*u(i,j+1)+2*h*g);
  20.             else
  21.                 u(i,j)=0.25*(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1));
  22.             end
  23.         end
  24.     end
  25. end
  26.  
  27. %SAIDA GRAFICA
  28. %DISTRIBUICAO DE POTENCIAL 3D
  29. ss=get(0,'ScreenSize');
  30. fig1=figure(1)
  31. set(fig1,'Position',ss,'Color',[1 1 1]);
  32. mesh(u), colormap(jet), colorbar
  33. label(1)=xlabel('x');
  34. label(2)=ylabel('y');
  35. label(3)=zlabel('u(x,y)');
  36. label(4)=title('Equacao de Laplace: uxx - uyy = 0');
  37. label(5)=legend('Diferencas Finitas',1);
  38. set(label,'FontSize',16);
  39. drawnow,pause(1)
  40.  
  41. %LINHAS EQUIPOTENCIAIS E DISTRIBUICAO DO CAMPO ELETRICO
  42. fig2=figure(2);set(fig2,'Position',ss,'Color',[1 1 1]);
  43. [x1,y1]=meshgrid(x,y);
  44. [px,py]=gradient(u,h,h/2);
  45. [c,h]=contour(x1,y1,u,[0.1:0.1:0.7]*V),cl=clabel(c,h);set(cl,'FontSize',14);
  46. colorbar; set(h,'Linewidth',2.5);
  47. hold on, s=1:2:n;
  48. g=quiver(x(s),y(s),-px(s,s),-py(s,s),0.7,'k-');
  49. hold off, set(g,'ShowArrowHead','on')
  50. label(1)=xlabel('x');
  51. label(2)=ylabel('y');
  52. label(3)=title('Equacao de Laplace: uxx + uyy = 0');
  53. label(4)=legend('Diferencas Finitas',1);
  54. set(label,'FontSize',16); axis([30 70 0 20])
  55. l(1)=line([40 60],[10 10]);
  56. l(2)=line([0 100],[0 0]);
  57. set(l,'Linewidth',5);
  58. drawnow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement