daily pastebin goal
40%
SHARE
TWEET

Exemplo 01: Eq. de Laplace c/ condições de cont. Dirichlet

fellpz Dec 7th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %IFPB 07/12/2017 - METODO DAS DIFERENCAS FINITAS
  2. %EXEMPLO 01: EQUACAO DE LAPLACE COM CONDICOES DE CONTORNO DE DIRICHLET
  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. %condicoes de contorno
  10. u=zeros(p,q);
  11. u(r,40:60)=V;
  12. %equacao de diferencas
  13. for iter=1:1000
  14.     for i=2:p-1
  15.         for j=2:q-1
  16.             if i==r & j>=40 & j<=60, u(r,j)=V;
  17.             else
  18.                 u(i,j)=0.25*(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1));
  19.             end
  20.         end
  21.     end
  22. end
  23.  
  24. %SAIDA GRAFICA
  25. %DISTRIBUICAO DE POTENCIAL 3D
  26. ss=get(0,'ScreenSize');
  27. fig1=figure(1)
  28. set(fig1,'Position',ss,'Color',[1 1 1]);
  29. mesh(u), colormap(jet), colorbar
  30. label(1)=xlabel('x');
  31. label(2)=ylabel('y');
  32. label(3)=zlabel('u(x,y)');
  33. label(4)=title('Equacao de Laplace: uxx - uyy = 0');
  34. label(5)=legend('Diferencas Finitas',1);
  35. set(label,'FontSize',16);
  36. drawnow,pause(1)
  37.  
  38. %LINHAS EQUIPOTENCIAIS E DISTRIBUICAO DO CAMPO ELETRICO
  39. fig2=figure(2);set(fig2,'Position',ss,'Color',[1 1 1]);
  40. [x1,y1]=meshgrid(x,y);
  41. [px,py]=gradient(u,h,h/2);
  42. [c,h]=contour(x1,y1,u,[0.1:0.1:0.7]*V),cl=clabel(c,h);set(cl,'FontSize',14);
  43. colorbar; set(h,'Linewidth',2.5);
  44. hold on, s=1:2:n;
  45. g=quiver(x(s),y(s),-px(s,s),-py(s,s),0.7,'k-');
  46. hold off, set(g,'ShowArrowHead','on')
  47. label(1)=xlabel('x');
  48. label(2)=ylabel('y');
  49. label(3)=title('Equacao de Laplace: uxx + uyy = 0');
  50. label(4)=legend('Diferencas Finitas',1);
  51. set(label,'FontSize',16); axis([30 70 0 20])
  52. l(1)=line([40 60],[10 10]);
  53. l(2)=line([0 100],[0 0]);
  54. set(l,'Linewidth',5);
  55. drawnow
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top