Search code examples
matlabpoissondecoupling

Coupled Poisson equations and Matlab program


can anyone help me solve it? Or help me uncouple the equations? :(

$u_{xx}+u_{yy}=au+bw$
$w_{xx}+w_{yy}=cu+dw$

Also I have to solve this problem using the finite difference method, but once i get the output everything's zero. This is my Matlab code, if anyone could help me with that. this is my code so far

clear; close all; 
n=101; h=1/(n-1);
x=0:h:1.01; y=0:h:1.01;
U=zeros(n+1); W=zeros(n+1);
omega=1.7777777;err=1000;
a1=0.5; a2=5; b1=-1; b2=1; 
tol=1e-6;
for i=1:n+1 %boundary conditions
    U(1,i)=cos(5*pi*y(i)); U(i,1)=cos(5*pi*y(i)); U(n+1,i)=0; U(i,n+1)=0;
    W(1,i)=cos(5*pi*y(i)); W(i,1)=cos(5*pi*y(i)); W(n+1,i)=0; W(i,n+1)=0;
end
figure(1);  
subplot(1,2,1);mesh(x,y,U);view(130,25);grid on; title('boundary conditions U(x,y)'); 
subplot(1,2,2);mesh(x,y,W);view(130,15);grid on; title('boundary conditions W(x,y)');  
u=U; w=W;
while err>tol
   for i=2:n
        for j=2:n
        u(i,j)=(1-omega)*U(i,j)+omega*(((u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1))/h^2)-b1*W(i,j))/(a1+(4/h^2));
        w(i,j)=(1-omega)*W(i,j)+omega*(((w(i+1,j)+w(i-1,j)+w(i,j+1)+w(i,j-1))/h^2)-a2*U(i,j))/(b2+(4/h^2));
        end
   end 
    W=w; U=u; err=max(max(abs(u-U))); 
end

figure(2);  
subplot(1,2,1);mesh(x,y,U);view(130,25);grid on; title('U(x,y)'); 
subplot(1,2,2);mesh(x,y,W);view(130,15);grid on; title('W(x,y)');    

Solution

  • The problem is this line:

     W=w; U=u; err=max(max(abs(u-U))); 
    

    You are setting U=u`` first and then looking at the different of uandU```. Reverse the computation and it works.

     err=max(max(abs(u-U))); W=w; U=u;