Iterative refinement of Ax=b equation to have a residual equal to 0

2 vues (au cours des 30 derniers jours)
Sean Murphy
Sean Murphy le 15 Mar 2013
I cant seem to figure out how to set up a for loop or while loop for find the least square solution to a problem when the residual is equal to zero. Any pointers?
clear all; close all;
% Given A, b, and ext
A = [21,67,88,73;
76,63,7,20;
0,85,56,54;
19.3,43,30.2,29.4];
b = [141;109;218;93.7];
ext = [-1;2;-3;4];
% LU factorization of A in single
[L1,U1] = lu(single(A));
% L1*U1*x=b ==> x=U1\(L1\b);
x1 = single(U1\(L1\b));
xs = double(x1);
save x1.dat xs -ascii
% norm of error
e1 = double(ext-xs);
e2 = double(norm(e1));
save error1.dat e2 -ascii
% residual
r1 = double(b-A*xs);
r2 = single(r1);
% solve Az=r ==> z=U1\(L1\r)
z = U1\(L1\r2);
x_s= xs + z;
% compute r and z as above until r=0
I'm not very good at while loops yet, but I am trying somewhere along the lines:
tol = 0;
while r4 < tol
r3 = double(b-A*x_s);
r4 = single(r3);
z1 = U1\(L1\r4);
x_s = x_s + z1;
end
  1 commentaire
Youssef  Khmou
Youssef Khmou le 15 Mar 2013
hi, i do not think you need loops, the sol is [-1 2-3 4] :
X=inv(A'*A)*A'*b

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by