Question

Modify the code for Jacobi_vs_GS.m to implement the Symmetric Gauss-Seidel iteration.



% Set number of iterations to be performed

nk = 300



% Set parameters alpha and beta

alpha = 2;

beta  = 3;



% Set the number of meshpoints so the interior has N x N such points

N = 50;



% Compute the distance between mesh points, in each direction

h = 1/(N+1);



% We will have arrays that capture the boundary as well as the interior

% meshpoints.  As a result, we need those arrays to be of size (N+2) x

% (N+2) so that those indexed 2:N+1, 2:N+1 represent the interior.  



% Compute the x-values at each point i,j, including the boundary

x = h * [ 0:N+1 ];   % Notice this creates a row vector



% Compute the y-values at each point i,j, including the boundary

y = h * [ 0:N+1 ];   % Notice this creates a row vector



% Create an array that captures the load at each point i,j

for i=1:N+2

for j=1:N+2

F( i,j ) = ...

( alpha^2 + beta^2 ) * pi^2 * sin( alpha * pi * x( i ) ) * sin( beta * pi * y( j ) );

end

end



% Set the initial values at the mesh points

U = zeros( N+2, N+2 );



% Perform nk iterations

for k = 1:nk

k           % print current iteration index



% update all the interior points

for i=2:N+1

for j=2:N+1

U( i,j ) = ( U( i, j-1 ) + U( i-1, j ) + U( i+1, j ) + U( i, j+1 ) + h^2 * F( i, j ) ) / 4;

end

end

mesh( x, y, U );

axis( [ 0 1 0 1 -1.5 1.5 ]);



% wait to continue to the next iteration

next = input( 'press RETURN to continue' );

end

close all


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Modify the code for Jacobi_vs_GS.m to implement the Symmetric Gauss-Seidel iteration.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • CONVERT THE FOLLOWING MATLAB CODE FROM SOURCE PANEL METHOD TO VORTEX PANEL METHOD: clc;clear all;...

    CONVERT THE FOLLOWING MATLAB CODE FROM SOURCE PANEL METHOD TO VORTEX PANEL METHOD: clc;clear all;close all; Vinf=100; % freestream velocity R=1; % cylinder radius n=4; % number of panels alpha=2; % angle of attack dtheta=2*pi/n; theta=pi+pi/n:-dtheta:-pi+pi/n; X=R*cos(theta); Y=R*sin(theta); for i=1:n % angle of flow with tangent of panel phi(i)=-alpha+atan2((Y(i+1)-Y(i)),(X(i+1)-X(i))); % angle of flow with normal of panel beta(i)=phi(i)+pi/2; x_mid(i)=(X(i+1)+X(i))/2; y_mid(i)=(Y(i+1)+Y(i))/2; S(i)=sqrt((Y(i+1)-Y(i))^2+(X(i+1)-X(i))^2); end % Source Panel Method for j=1:n neighbors(:,j)=[1:j-1 j+1:n]; xi=x_mid(j); yi=y_mid(j); for i=1:n-1 m=neighbors(i,j); Xj=X(m); Yj=Y(m); Xj1=X(m+1); Yj1=Y(m+1); A=-(xi-Xj)*cos(phi(m))-(yi-Yj)*sin(phi(m));...

  • Modify the given code below which uses Simpson's 3/8 method with 6 subintervals to answer the...

    Modify the given code below which uses Simpson's 3/8 method with 6 subintervals to answer the question above. if a==b I=0 else N=3; h=(b-a)/N; x=a:h:b; y=Fun(x); I=3*h/8*(y(1)+2*sum(y(4:3:(N-2)))+y(N+1)); N=2*N; check=0; % Calculating subsequent valus of I while check==0; h=(b-a)/N; x=a:h:b; y=Fun(x); % Composite Simpson's 3/8 method, Eq. (9.22) I_new=3*h/8*(y(1)+2*sum(y(4:3:(N-2)))+y(N+1)); I_new=I_new+3*h/8*3*(sum(y(2:3:(N-1)))+sum(y(3:3:N))); % Compare solution with that calculated in the previous iteration error=abs((I-I_new)/I)*100; % (*) if error>0.1 % continue iteration check=0; N=N*2; I=I_new; elseif error<=0.1 % end iteration check=1; I=I_new; end end end...

  • (c) (Optional) Calculate the fo/2 Padé approximant to e, where θ is rea I. Show that the leading-order error is θ3/...

    (c) (Optional) Calculate the fo/2 Padé approximant to e, where θ is rea I. Show that the leading-order error is θ3/6 Consider Eq. (1), with U = 0 at x = 0 and x 1, approximated at the mesh points xm-Tnh, mに1 N-1, Nh = 1, along the time level tn nk by the set of difference equations and λ = k/h2, and TN-1 is the matrix of order N-1 repre- senting the second order operator 62 Investigate the stability...

  • 4. (20 pts) Suppose the boundary-value problem y" – y=x, 0 < x < 1; y(0)...

    4. (20 pts) Suppose the boundary-value problem y" – y=x, 0 < x < 1; y(0) = y'(1) = 0 Let h = 1/n, X; = jh, where j = 0,1,..., n and u; y(x;). Consider two "exterior" mesh points 2-1 = -h and 2n+1 = 1+h. Write out an 0(ha) approximate linear tridiagonal system for {u}. Hint: Let u-1 = y(x-1) = y(-h) and Un+1 = y(2n+1) = y(1 + h). Then using f(a+h) – f(a – h). f'(a)...

  • Question 1 [Total 20 marks] (a) [5 marks] In a steady-state two-dimensional heat flow problem, th...

    Question 1 [Total 20 marks] (a) [5 marks] In a steady-state two-dimensional heat flow problem, the temperature, u, at any point in the domain (t, ) satisfies the differential equation u y(2-y) u= U0F With the given temperature boundary condition as follows: u(x, 0) = 0, u(x, 2) = x(4-x), 0 < x < 4 Calculate the temperature at the interior points a, b, and c using a mesh size h-1. Question 1 [Total 20 marks] (a) [5 marks] In...

  • Solve Laplace's equation on

    Solve Laplace's equation on \(-\pi \leq x \leq \pi\) and \(0 \leq y \leq 1\),$$ \frac{\partial^{2} u}{\partial x^{2}}+\frac{\partial^{2} u}{\partial y^{2}}=0 $$subject to periodic boundary conditions in \(x\),$$ \begin{aligned} u(-\pi, y) &=u(\pi, y) \\ \frac{\partial u}{\partial x}(-\pi, y) &=\frac{\partial u}{\partial x}(\pi, y) \end{aligned} $$and the Dirichlet conditions in \(y\),$$ u(x, 0)=h(x), \quad u(x, 1)=0 $$

  • Use the following pseudocode for the Newton-Raphson method to write MATLAB code to approximate the cube...

    Use the following pseudocode for the Newton-Raphson method to write MATLAB code to approximate the cube root (a)1/3 of a given number a with accuracy roughly within 10-8 using x0 = a/2. Use at most 100 iterations. Explain steps by commenting on them. Use f(x) = x3 − a. Choose a = 2 + w, where w = 3 Algorithm : Newton-Raphson Iteration Input: f(x)=x3−a, x0 =a/2, tolerance 10-8, maximum number of iterations100 Output: an approximation (a)1/3 within 10-8 or...

  • Solve Laplace's equation

    Solve Laplace's equation, \(\frac{\partial^{2} u}{\partial x^{2}}+\frac{\partial^{2} u}{\partial y^{2}}=0,0<x<a, 0<y<b\), (see (1) in Section 12.5) for a rectangular plate subject to the given boundary conditions.$$ \begin{gathered} \left.\frac{\partial u}{\partial x}\right|_{x=0}=u(0, y), \quad u(\pi, y)=1 \\ u(x, 0)=0, \quad u(x, \pi)=0 \\ u(x, y)=\square+\sum_{n=1}^{\infty}(\square \end{gathered} $$

  • Please complete using matlab In this problem you will utilize a for loop to compute the...

    Please complete using matlab In this problem you will utilize a for loop to compute the an approximation of the value of using the Leibniz's formula for Pi. The formula uses a summation. Follow the instructions correctly and read the questions thoroughly. 1. Set up the initial number of iteration i to obtain six iterations. 2. The approximate value of it can be given by the following formula: Approximated = Enzo 2n+1 Where n is an integer starting at zero...

  • PLEASE USE MATLAB. The code is basically given to you with the algorithm above. Write a...

    PLEASE USE MATLAB. The code is basically given to you with the algorithm above. Write a program for solving the system Ar-b by using Gauss-Seidel iterative method discussed in class that uses a computer memory for one iterate only. This could be summarized as follows: Input n -- the size of the system, matrix A-(a(i,j), the vectoir b (b (1), . . . , b(n)), the intitial guess x (x(1), ..., x(n)) (you can use x=b) maximum number of iterations...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT