Implementing Richardson's Iterative Method

조회 수: 12 (최근 30일)
cee878
cee878 2016년 3월 17일
댓글: Geoff Hayes 2016년 3월 19일
I'm trying to implement Richardson's iterative method to solve Ax=b equation. I want to see the values in my matrix. But I wrote it in a way, that I don't know how to do it. I thought about writing it as three separate equations instead of vector form, but I'm not quite sure how you would do that. This is my current code:
format long
A = [9 1 1;
2 10 3;
3 4 11];
b = [10;
19;
0];
x = [0;
0;
0];
G=eye(3)-A; %I-A
z = [0,x'];
for k=1:30
x = G*x + b;
z = [k,x'];
end
fprintf('Number of Iterations: %d \n', k);
display(z);

답변 (1개)

Geoff Hayes
Geoff Hayes 2016년 3월 18일
Chris - are you trying to see the evolution of x over all iterations? Is that why you have the
z = [k, x'];
to give the x for the kth iteration? If so, then you could replace the above with
z = [z ; [k x']];
so that we always concatenate the new values to the previous ones. Try the above and see what happens!
  댓글 수: 3
cee878
cee878 2016년 3월 18일
Also, could you tell me how to restrict the values to 6 decimal places, when I'm trying to print the values out?
Geoff Hayes
Geoff Hayes 2016년 3월 19일
Chris - on each iteration of the loop, we add a row to z by concatenating the new row to the previous ones as
z = [k, x'];
Use the debugger to step through the code and see this happen.
As for restricting the values to 6 decimal places, see fprintf and in particular the format specification. For a single floating point value, you would do something like
fprintf('pi to six decimals is %.6f\n',pi);

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

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by