Advertisement
fellpz

Exemplo 2. Equação de Poisson

Nov 30th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.42 KB | None | 0 0
  1. % IFPB 30/11/2017
  2. % EQUAÇÃO DE POISSON COMK CONDIÇÕES DE CONTORNO DE DIRICHLET
  3. % Uxx - Uyy = 4
  4. % Condições de contorno
  5. % U(x,1)=x^2+1 e U(x,-1)=x^2+1, U(1,y)=y^2+1, U(-1,y)=y^2+1
  6. % Aproximação no quadrado [-1;1]x[-1;1]
  7. % Solução analítica u(x,y)=x^2+y^2
  8.  
  9. close all, clear all, clc;
  10.  
  11. % malha computacional bidiminensional
  12. n=100;  h=2/(n-1); x=-1:h:1; y=x;
  13.  
  14. % Condições de contorno
  15. u=zeros(n);
  16. u(1,:)=y.^2+1; u(n,:)=y.^2+1;
  17. u(:,1)=x.^2+1; u(:,n)=x.^2+1;
  18.  
  19. % Equação de diferenças
  20. for iter=1:1000,    for i=2:n-1,    for j=2:n-1
  21.             u(i,j)=0.25*(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1)-h^2*4);
  22.         end, end, end
  23.  
  24. fig1=figure(1); set(fig1,'Position',[1 33 1024 662],'Color',[1 1 1]);
  25. surfc(u), shading interp
  26. label(1)=xlabel('x'); label(2)=ylabel('y');
  27. label(3)=zlabel('u(x,y)');
  28. label(4)=title('Equação de Poisson: Uxx - Uyy = f');
  29. label(5)=legend('Diferenças Finitas',1);
  30. set(label, 'FontSize',16); drawnow,pause(1)
  31.  
  32. fig2=figure(2); set(fig2,'Position',[1 33 1024 662],'Color',[1 1 1]);
  33. [x1,y1] = meshgrid(x,y); [px,py] = gradient(u,h,h);
  34. [c,h] = contour(x1,y1,u);
  35. cl=clabel(c,h); set(cl,'FontSize', 14);
  36. colorbar; set(h,'Linewidth', 2.5);
  37. hold on, s=1:10:100;
  38. quiver(x(s),y(s),-px(s,s),-py(s,s)), hold off,
  39. label(1)=xlabel('x'); label(2)=ylabel('y');
  40. label(3)=title('Equação de Poisson: Uxx - Uyy = f');
  41. label(4)=legend('Diferenças Finitas',1);
  42. set(label, 'FontSize',16); drawnow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement