Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %IFPB 07/12/2017 - METODO DAS DIFERENCAS FINITAS
- %EXEMPLO 01: EQUACAO DE LAPLACE COM CONDICOES DE CONTORNO DE DIRICHLET
- %LINHA DE MICROFITA SUSPENSA NO AR
- close all, clear all, clc;
- %malha computacional bidimensional
- n=100; r=10; V=100;
- p=n; q=n; x=1:n; y=x; h=1;
- %condicoes de contorno
- u=zeros(p,q);
- u(r,40:60)=V;
- %equacao de diferencas
- for iter=1:1000
- for i=2:p-1
- for j=2:q-1
- if i==r & j>=40 & j<=60, u(r,j)=V;
- else
- u(i,j)=0.25*(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1));
- end
- end
- end
- end
- %SAIDA GRAFICA
- %DISTRIBUICAO DE POTENCIAL 3D
- ss=get(0,'ScreenSize');
- fig1=figure(1)
- set(fig1,'Position',ss,'Color',[1 1 1]);
- mesh(u), colormap(jet), colorbar
- label(1)=xlabel('x');
- label(2)=ylabel('y');
- label(3)=zlabel('u(x,y)');
- label(4)=title('Equacao de Laplace: uxx - uyy = 0');
- label(5)=legend('Diferencas Finitas',1);
- set(label,'FontSize',16);
- drawnow,pause(1)
- %LINHAS EQUIPOTENCIAIS E DISTRIBUICAO DO CAMPO ELETRICO
- fig2=figure(2);set(fig2,'Position',ss,'Color',[1 1 1]);
- [x1,y1]=meshgrid(x,y);
- [px,py]=gradient(u,h,h/2);
- [c,h]=contour(x1,y1,u,[0.1:0.1:0.7]*V),cl=clabel(c,h);set(cl,'FontSize',14);
- colorbar; set(h,'Linewidth',2.5);
- hold on, s=1:2:n;
- g=quiver(x(s),y(s),-px(s,s),-py(s,s),0.7,'k-');
- hold off, set(g,'ShowArrowHead','on')
- label(1)=xlabel('x');
- label(2)=ylabel('y');
- label(3)=title('Equacao de Laplace: uxx + uyy = 0');
- label(4)=legend('Diferencas Finitas',1);
- set(label,'FontSize',16); axis([30 70 0 20])
- l(1)=line([40 60],[10 10]);
- l(2)=line([0 100],[0 0]);
- set(l,'Linewidth',5);
- drawnow
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement