SOR Method not running correctly

Hey guys I included my code below as well as a screenshot of the problem I am supposed to be doing. Why is this coming out as a flat surface?
% HW 8
dx = .01; dy = .01;
x = 0:dx:5; y = 0:dy:4;
imax = length(x); jmax = length(y);
%D=2; a = .3; b = .4; c = 1;
%alpha = D*(2/dx^2+2/dy^2)-c;
S = @(x,y) -800*(exp(-10*(((x-1)^2) + ((y-2)^2))));
u = zeros(imax,jmax);
error = 0;
omega = 1.95;
itermax = 4000;
tol = 100;
iter = 1;
D=2; a = .3; b = .4; c = 1;
alpha = D*(2/dx^2+2/dy^2)-c;
H = @(y) 50 + 2*y;
Q = @(x) 50 - 3*x;
while (iter < itermax && error > tol)
error = 0;
z = @(x) g(x);
z = 50 + x;
if (1 <= x && x <= 3)
z = 100;
end
F(x) = @(y) 50 -y;
u(1,1) = (1/2)*(F(1) + g(1));
for i = 2:jmax - 1
u(i,1) = g(i);
end
u(imax,1) = (1/2)*(g(imax) + H(1));
for j = 2:jmax - 1
u(1,jmax) = F(jmax);
for i = 2:imax - 1
T = D*((u(i-1,j)+u(i+1,j))/dx^2+(u(i,j-1)+u(i,j+1))/dy^2) ...
+ a*(u(i+1,j)-u(i-1,j))/(2*dx) + b*(u(i,j+1)-u(i,j-1))/(2*dy) ...
+ S(x(i),y(j));
R = T/alpha - u(i,j);
error = error + abs(R);
u(i,j) = u(i,j) + omega*R;
end
u(imax,jmax) = H(jmax);
end
iter = iter + 1;
end
mesh(x,y,u')

Answers (0)

Tags

Asked:

on 28 Apr 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!