Gauss-Siedel Matrix to solve Elliptic Equation

  • MHB
  • Thread starter ra_forever8
  • Start date
  • Tags
    Matrix
In summary, the conversation involves writing a FORTRAN program to solve an elliptic equation using the five-point finite difference formula in a right-angled triangle with specific boundary conditions and mesh spacing. The program also involves using the Gauss-Seidel matrix solver and linear interpolation on the long side of the triangle. The program includes initial conditions, a loop to calculate the error, and a loop to calculate the approximate solution. The output of the program includes the approximate solution and a plot of the solution using MATLAB. The final steps involve determining the values for alpha, beta, a, and b, which are used in the calculation of points outside the long side of the triangle in the five-point scheme.
  • #1
ra_forever8
129
0
Qs: Write a FORTRAN program to approximately solve elliptic equation : - u_xx - u_yy=1 with the five-point finite difference formula in the right-angled triangle, sides 1,2,3^(1/2) using the Gauss-Seidel matrix solver withe the boundary conditions u=0 on all sides. Take a mesh spacing to be h=0.01. (You'll need linear interpolation on the long side.)

=>
Code:
  PROGRAM Gauss_Seidel
IMPLICIT NONE

! Declare Variables
Real, allocatable :: x(:),y(:),u(:,:),u_old(:,:)
Real:: h,tolerence,error
Integer:: i,j,JI,NI

h=0.01
JI=100
NI=173
error = 1.d0
tolerence = 10E-4
 ! Total number of space stepsize
allocate (x(0:JI),y(0:NI),u(0:JI+1,0:NI+1),u_old(0:JI+1,0:NI+1))
open(10,file='Gauss_Seidel.m')  !Opening files in Matlab

!Initial Conditions
x(0)= 0
x(JI)= 1.0
y(0)= 0
y(NI)= SQRT(3.0)

do i=0,JI
do j=0,NI
x(i)= i*h   ! x-axix, x starts from 0 to 1 
y(j)= j*h   ! y-axis  y starts from 0 to SQRT(3.0)
u(i,j)= 0         ! Entire Boundary is zero
end do
end do

while (error .GT. tolerence) do  ! To stop
  do i=1, JI-1
    do j=1,NI-1
u_old(i,j)= u(i,j)  ! To [U][SIZE=2][COLOR=#009900]store[/COLOR][/SIZE][/U] the old values

!Using 5-point scheme Formulae and rearranging the equation
u(i,j)= 0.25*(u(i+1,j)+u(i,j+1)+u(i-1,j)+u(i,j-1)+h**2) 
     end do
     end do

error =0.d0        ! Now, error reading the value of zero
     do i=1,JI-1
       do j=1, NI-1
error = error + abs(u(i,j)- u_old(i,j))  ! To Stop
        end do
         end do
        end do

 do i=1, JI-1
    do j=1,NI-1

 u(i+1,j)= - (alpha * u(i,j))/ beta    ! lies outside the long side
 u(i,j+1)= - (a * u(i,j))/ b           ! lies outside the long side
 
     end do
     end do
!Print out the Approximate solution in MATLAB to get output and plot 
write(10,*)  'x=['                           
     do i=0, JI
       write(10,*) x(i)
 end do
write(10,*) ']'

write(10,*)  'y=['                           
       do j=0,NI
write(10,*) y(j)
 end do
write(10,*) ']'

write(10,*)  'u=['                           
     do i=0, JI
       do j=0,NI
write(10,*) u(i,j)
 end do
 end do
write(10,*) ']'

write(10,*) "[X,Y] = meshgrid(x,y)"              !Ploting diagram x,y,u
write(10,*) "Z=reshape(u,length(y), length(x))"
write(10,*) "contour(X,Y,Z)"
write(10,*) "xlabel('x'),ylabel('y'),legend('Approximate Gauss Seidel')"
close(10) 

END PROGRAM Gauss_Seidel

(Note: THIS IS WHAT I HAVE GOT SO FAR, STILL LITTLE BIT INCOMPLETE.
THE LENGTH OF THE LONG SIDE OF THE TRIANGLE IS 2. SINCE THE POINTS ON THE LONG SIDE DO NOT COINCIDE WITH THE GRID POINTS, THE POINTS u(i,j+1) and u(i+1,j) lies outside the long side of the triangle, the distance between the points u(i,j) to u(i,j+1) and u(i,j) to u(i+1,j) are zero which is known using the linear interpolation. Alpha is the distance from zero to point u(i + 1, j) and beta is the distance from point u(i, j) to zero.
Similarly, a is the distance from zero to point u(i, j+1) and b is the distance from point u(i, j) to zero.
The points u(i -1, j) and u(i, j - 1) lies inside the long side of the triangle, the distance from these points to u(i, j) remains unchanged and does not affect in the five-point scheme.
Can anyone help me after this. What can do with alpha, beta,a and b? Do I need to know values for alpha,beta, a and b?
Please help me )
 
Physics news on Phys.org
  • #2


In order to complete the program, you will need to calculate the values for alpha, beta, a, and b. These values represent the distances from the grid points to the long side of the triangle, and they will affect the calculation of the five-point scheme.

To calculate these values, you can use linear interpolation. This involves finding the distance between the grid points and the long side, and then using that distance to calculate the distances to the points u(i+1,j) and u(i,j+1).

Once you have calculated these values, you can use them in the equations for u(i+1,j) and u(i,j+1) in the program. This will ensure that the calculation takes into account the points that lie outside the long side of the triangle.

You can also use these values to plot the approximate solution in MATLAB, as shown in the program. This will help you visualize the solution and make any necessary adjustments to the program.

Overall, the key to completing this program is to accurately calculate the values for alpha, beta, a, and b. Once you have these values, you can use them in the program and plot the solution to see if it matches the expected solution for the given boundary conditions and equation.
 

FAQ: Gauss-Siedel Matrix to solve Elliptic Equation

What is the Gauss-Siedel method for solving elliptic equations?

The Gauss-Siedel method is an iterative numerical method used to solve systems of linear equations, particularly in the context of solving elliptic equations. It involves repeatedly updating the values of the unknown variables using a specific algorithm until a certain level of accuracy is achieved.

How does the Gauss-Siedel method differ from other methods of solving elliptic equations?

The main difference between the Gauss-Siedel method and other methods, such as the Jacobi method, is that it uses the updated values of the unknown variables in each iteration, rather than waiting until the end of the iteration to update all the values at once. This results in faster convergence and greater efficiency.

What are the advantages of using the Gauss-Siedel method for solving elliptic equations?

One of the main advantages of the Gauss-Siedel method is its simplicity and ease of implementation. It also has a faster convergence rate compared to other methods, especially for large systems of equations. Additionally, it can handle both diagonally dominant and non-diagonally dominant systems of equations, making it a versatile method.

Are there any limitations of the Gauss-Siedel method?

There are a few limitations to the Gauss-Siedel method. Firstly, it may not converge for certain systems of equations with complex eigenvalues. Additionally, it may not converge if the iteration matrix is not strictly diagonally dominant. Lastly, the method may give inaccurate results for ill-conditioned systems of equations.

Can the Gauss-Siedel method be applied to nonlinear systems of equations?

Yes, the Gauss-Siedel method can be extended to solve nonlinear systems of equations, known as the Gauss-Siedel fixed point method. However, it may require additional iterations and may not always converge to a solution. Other methods, such as Newton's method, may be more suitable for solving nonlinear systems of equations.

Similar threads

Replies
41
Views
9K
Replies
3
Views
3K
Replies
2
Views
3K
Replies
18
Views
3K
Replies
4
Views
2K
Replies
1
Views
3K
Back
Top