필터 지우기
필터 지우기

Simple relaxation method Matlab

조회 수: 17 (최근 30일)
Rolland-Luigi Eva
Rolland-Luigi Eva 2023년 2월 9일
댓글: Rolland-Luigi Eva 2023년 2월 9일
Hi.
I want to solve an ecuation system using the simple relaxation method.
I wrote the code using an exemple but the result is wrong. ( Or null? )
A=[ 67 -8 -3 78; -8 65 12 12 ; -3 12 64 -17; 78 12 -17 61];
b=[4; 6 ; 8 ;10];
n=length (b);
x=zeros (n,1) ;
r=A*x-b;
while norm (r, inf) > (10^ (-10) )
p=zeros (n,1);
[c, j]=max(abs (r) );
p ( j) =1;
t= ( -r (j) ) / A (j,j) ;
x=x+t*p;
r=A*x-b;
end
x
i
This is what I have managed to write and the result is NaN, NaN, NaN, Inf.
Is there anything I'm doing wrong? I apologise if this seems like a silly question. I'm just new into it and trying to discover how to solve it.
Thank you! I have tried both r2009a and the online version.
  댓글 수: 2
Torsten
Torsten 2023년 2월 9일
Never seen this iteration scheme. Does it have a name ? Can you give a link where it is described ?
Rolland-Luigi Eva
Rolland-Luigi Eva 2023년 2월 9일
Unfortunately it is not described, probably that's why I could't solve it, I didn't understand the solving steps properly.
It is from an university course.

댓글을 달려면 로그인하십시오.

채택된 답변

Alan Stevens
Alan Stevens 2023년 2월 9일
편집: Alan Stevens 2023년 2월 9일
For the simple relaxation technique to work the A matrix needs to be diagonally dominant. Your A is not diagonally dominant - see first and last rows.
For example, if we make A diagonally dominant (I've just arbitrarily modified your A so that it is), your program generates the following:
A=[ 78 -8 -3 67; -8 65 12 12 ; -3 12 64 -17; 61 12 -17 78];
b=[4; 6 ; 8 ;10];
n=length (b);
x=zeros (n,1) ;
r=A*x-b;
while norm (r, inf) > (10^ (-10) )
p=zeros (n,1);
[c, j]=max(abs (r) );
p ( j) =1;
t= ( -r (j) ) / A (j,j) ;
x=x+t*p;
r=A*x-b;
end
disp(x)
-0.3524 -0.0841 0.2494 0.4711
Compare this with
disp(A\b)
-0.3524 -0.0841 0.2494 0.4711
  댓글 수: 3
John D'Errico
John D'Errico 2023년 2월 9일
@Rolland-Luigi Eva - What you said is not technically correct. The system of equations DOES have a solution.
A=[ 78 -8 -3 67; -8 65 12 12 ; -3 12 64 -17; 61 12 -17 78];
b=[4; 6 ; 8 ;10];
x = A\b
x = 4×1
-0.3524 -0.0841 0.2494 0.4711
That is the solution of that system of equations. It is just not achievable using a simple relaxation scheme, as that appears to be divergent for this problem.
norm(A*x-b)
ans = 3.9721e-15
So zero to within floating point trash for the problem.
The problem is that some linear systems of equations will not converge under a relaxation scheme.
Rolland-Luigi Eva
Rolland-Luigi Eva 2023년 2월 9일
Yes, it couldn't been solved using the method I wanted to.
I apologise.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

제품


릴리스

R2009a

Community Treasure Hunt

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

Start Hunting!

Translated by