Implementing Richardson's Iterative Method
36 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!