# Laplace Eq. Numerical Sol. with SOR Method-MATLAB Code

 Register Blogs Members List Search Today's Posts Mark Forums Read April 3, 2020, 15:27 Laplace Eq. Numerical Sol. with SOR Method-MATLAB Code #1 New Member   jist Join Date: Feb 2020 Posts: 3 Rep Power: 5 Hi all, I've been given analytical solution of U=x^2-y^2 which satisfies the Laplace Eq. and its numerical solution as S for a square domain. Boundary conditions setted from analytical solution 'U' and unchanged through the code. Internal points of S taken as 0 at initial. Then i am asked that to perform 20 iterations of SOR method with relaxation factor (omega) changing 1 to 2 with an interval of 0.002. I should've been able to calculate error between analytical and numerical solution for each relaxation factor at the end of 20th iteration with given MATLAB code below but errors do not match with the solution at all. Can anybody tell me what is it that i am doing wrong? Thanks in advence. Here is my code, Code: clc close all clear all N=21; iteration=20; deltax=1/(N-1); deltay=deltax; delomega=0.002; omegai=1; Nomega=1/(0.002); x=linspace(0,1,21); y=linspace(0,1,21); omega=linspace(1,2,Nomega); %analytical solution u=zeros(N,N); for j=1:N for i=1:N u(i,j)=x(i)^2-y(j)^2; end end s=zeros(N,N); s(1,:)=u(1,:); s(N,:)=u(N,:); s(:,1)=u(:,1); s(:,N)=u(:,N); error=0; for k=1:Nomega for l=1:iteration for j=2:N-1 for i=2:N-1 R=s(i+1,j)+s(i-1,j)+s(i,j+1)+s(i,j-1)-4*(s(i,j))-(deltax^2)*s(i,j); s(i,j)=s(i,j)+0.25*(1+delomega*k)*R; end end if l==iteration error=error+abs(u(i,j)-s(i,j)); %error_(k,1)=omega(k); error_(k)=error/((N-2)*(N-2)); end end end plot(omega(:),error_(:)); xlabel('\omega'); ylabel('Error'); grid on grid minor   April 3, 2020, 15:30 #2 Senior Member   Filippo Maria Denaro Join Date: Jul 2010 Posts: 6,398 Rep Power: 67   First, correct "U=x^2+y^2" in "U=x^2-y^2", otherwise the solution does not satisfy the Laplace euqation. Then, why do you think to get an accurate solution after only 20 iterations??   April 3, 2020, 15:52 #3
New Member

jist
Join Date: Feb 2020
Posts: 3
Rep Power: 5 Sorry for the typo, it was x^2-y^2 as stated in the code.
Well this part is not about how to get an accurate solution via iteration. I will simply run the code for smaller mesh sizes to see how mesh sizes impact the solution.

Quote:
 Originally Posted by FMDenaro First, correct "U=x^2+y^2" in "U=x^2-y^2", otherwise the solution does not satisfy the Laplace euqation. Then, why do you think to get an accurate solution after only 20 iterations??   April 3, 2020, 16:19 #4
Senior Member

Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,398
Rep Power: 67   Quote:
 Originally Posted by jist Sorry for the typo, it was x^2-y^2 as stated in the code. Well this part is not about how to get an accurate solution via iteration. I will simply run the code for smaller mesh sizes to see how mesh sizes impact the solution.

You wrote "but errors do not match with the solution at all."   April 3, 2020, 17:44 #5
New Member

jist
Join Date: Feb 2020
Posts: 3
Rep Power: 5 I have the solution plot (error as a function of omega and grid sizes) for the scenario i explained but i am not getting the same results. What i tried to ask was that am i doing anything wrong with SOR or the error between analytical and numerical solution?
Quote:
 Originally Posted by FMDenaro You wrote "but errors do not match with the solution at all."   April 3, 2020, 18:02 #6 Senior Member   Filippo Maria Denaro Join Date: Jul 2010 Posts: 6,398 Rep Power: 67   You have a 2D map of the error as function of two variables. Plot the contour and the surface and check for the values producing the minimum error. Be aware that you cannot see a decreasing of the error for smaller mesh sizes.  Tags laplace equation, matlab code, relaxation factor, sor Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules Similar Threads Thread Thread Starter Forum Replies Last Post hymadyapa Main CFD Forum 4 November 28, 2019 00:59 mikasa Main CFD Forum 7 April 19, 2017 08:00 raminostadi ANSYS 0 February 6, 2017 05:16 behrouz Main CFD Forum 3 September 16, 2015 09:53 Mojtaba.a FLUENT 0 January 27, 2015 07:56

All times are GMT -4. The time now is 07:09.