Current location - Education and Training Encyclopedia - Graduation thesis - Jacobian iterative paper
Jacobian iterative paper
The following is what I wrote, please feel free to use it ~ ~ ~

% Super Relaxation Iteration (Sorting Method)

function [x k flag]=SOR(A,b,eps,w,maxl)

%A is the coefficient matrix of the equation.

%b is the right vector of the equation.

Accuracy requires %eps.

%maxl is the maximum number of iterations and the default value is 100.

%w is the super relaxation factor, and the default value is 1.

%x is the solution of the system of equations

%k is the number of iterations

%flag is an indicator variable.

Initial value of% allocation:

If narrow & lt5maxl =100; end

If narrow & lt4w =1; end

If narrow & LT3EPS =1e-5; end

N = length (b); k = 0;

X = zero (n,1); Y = zero (n,1); flag = ' OK

% start iteration:

Although it is true.

y = x; % y and z are both auxiliary variables.

For i= 1:n

z = b(I);

For j= 1:n

If j~=i

z=z-A(i,j)* x(j);

end

end

If abs(A(i, I)) <; 1e- 10|k==maxl

Flag= "failed"; Return;

end

z=z/A(i,I); x(I)=( 1-w)* x(I)+w * z;

end

if norm(y-x,INF)& lt; storage battery

Break;

end

k = k+ 1;

end

%Jacobi iterative method for solving linear equations

function [x k flag]=Jacobi(A,b,eps,maxl)

%A is the coefficient matrix of the equation.

%b is the right vector of the equation.

Accuracy requires %eps.

%maxl is the maximum number of iterations and the default value is 100.

%x is the solution of the system of equations

%k is the number of iterations

%flag is an indicator variable.

Initial value of% allocation:

If narrow & lt4maxl =100; end

If narrow & LT3EPS =1e-5; end

N = length (b); k = 0;

X = zero (n,1); Y = zero (n,1); flag = ' OK

% start iteration:

And 1

For i= 1:n

y(I)= b(I);

For j= 1:n

If j~=i

y(i)=y(i)-A(i,j)* x(j);

end

end

If abs(A(i, I)) <; 1e- 10|k==maxl

Flag= "failed"; Return;

end

y(i)=y(i)/A(i,I);

end

if norm(y-x,INF)& lt; storage battery

Break;

end

x = y; k = k+ 1;

end

I am sure I can pass a little debugging. It's all tested. Remember to grade me. Thank you ~ ~ ~