Implementing Richardson's Iterative Method

13 Ansichten (letzte 30 Tage)
cee878
cee878 am 17 Mär. 2016
Kommentiert: Geoff Hayes am 19 Mär. 2016
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);

Antworten (1)

Geoff Hayes
Geoff Hayes am 18 Mär. 2016
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 Kommentare
cee878
cee878 am 18 Mär. 2016
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 am 19 Mär. 2016
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);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Linear Algebra finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by