Implementing Richardson's Iterative Method
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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);
0 commentaires
Réponses (1)
Geoff Hayes
le 18 Mar 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 commentaires
Geoff Hayes
le 19 Mar 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);
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!