Using MATLAB, setup and run the error minimization approach to solving the syste
ID: 3800517 • Letter: U
Question
Using MATLAB, setup and run the error minimization approach to solving the system of equations , writing out the estimate at each iteration along with the error.
2/3 x + y + 1/2 z = 3
1/2 x + 2/3 y + z = 2
x + 1/2 y + 2/3 z = 1
Prototype:
// Open file for recording output
// Then compute
Iter = // ( I - mu * A' * A )
bIter = // and mu * A' * b
x = // random data.
for k = 0:100
// Perform iteration.
y = Iter * x + bIter;
// Compute error vector
e = A*x – b;
e = e' * e; // The sum squared error
// Replace x with y.
x = y;
// Write x, and error to the previously opened file.
// Exit if sqrt( e ) < 3 * eps
end
i+1Explanation / Answer
fileID = fopen('e:sol1.txt','w');
%Open file for recording output
%Then compute
I = [1 0 0;0 1 0;0 0 1];
A = [2/3 1 1/2;1/2 2/3 1;1 1/2 2/3];
b = [3;2;1];
mu = 0.3;
Iter = ( I - mu.*(A' * A) );
bIter = mu.* (A' * b);
x = [2;3;5]; %random data.
for k = 0:100
%Perform iteration.
y = Iter*x + bIter;
%Compute error vector
e = A*x - b;
e = e' * e; %The sum squared error
% Replace x with y.
x = y;
%Write x, and error to the previously opened file.
fprintf(fileID, '%f %f %f ',x);
if sqrt( e ) < 3 * eps
break;
end
end
fclose(fileID);
%------------------------------------------------------------------------------------------------
Output in text file
-1.416667 -0.225000 1.458333
-0.051528 1.320625 2.705764
-0.637209 0.904901 2.009240
-0.424658 1.277496 2.117415
-0.536500 1.316361 1.907286
-0.514420 1.480358 1.836811
-0.545649 1.582767 1.718427
-0.553815 1.700444 1.628191
-0.570178 1.802582 1.534544
-0.582044 1.902305 1.449902
-0.594665 1.994764 1.368751
-0.605959 2.082420 1.292925
-0.616835 2.164722 1.221280
-0.626978 2.242321 1.153914
-0.636570 2.315353 1.090437
-0.645586 2.384142 1.030679
-0.654082 2.448911 0.974400
-0.662081 2.509905 0.921407
-0.669613 2.567340 0.871504
-0.676706 2.621425 0.824513
-0.683386 2.672354 0.780262
-0.689675 2.720313 0.738593
-0.695598 2.765474 0.699355
-0.701175 2.808001 0.662405
-0.706427 2.848047 0.627611
-0.711373 2.885757 0.594846
-0.716030 2.921268 0.563993
-0.720415 2.954707 0.534940
-0.724545 2.986195 0.507581
-0.728434 3.015846 0.481818
-0.732096 3.043768 0.457558
-0.735544 3.070061 0.434714
-0.738791 3.094820 0.413202
-0.741849 3.118135 0.392944
-0.744728 3.140090 0.373869
-0.747439 3.160764 0.355906
-0.749993 3.180233 0.338991
-0.752397 3.198565 0.323062
-0.754661 3.215828 0.308063
-0.756793 3.232085 0.293939
-0.758801 3.247392 0.280639
-0.760691 3.261807 0.268114
-0.762471 3.275381 0.256321
-0.764148 3.288164 0.245215
-0.765726 3.300200 0.234757
-0.767213 3.311535 0.224909
-0.768612 3.322208 0.215635
-0.769931 3.332259 0.206903
-0.771172 3.341723 0.198679
-0.772341 3.350635 0.190936
-0.773441 3.359028 0.183644
-0.774478 3.366931 0.176778
-0.775454 3.374373 0.170312
-0.776373 3.381380 0.164223
-0.777238 3.387979 0.158490
-0.778053 3.394193 0.153091
-0.778821 3.400045 0.148006
-0.779543 3.405555 0.143219
-0.780224 3.410744 0.138711
-0.780864 3.415630 0.134465
-0.781468 3.420231 0.130468
-0.782036 3.424564 0.126703
-0.782571 3.428644 0.123158
-0.783075 3.432486 0.119820
-0.783550 3.436103 0.116677
-0.783996 3.439510 0.113717
-0.784417 3.442718 0.110930
-0.784813 3.445739 0.108305
-0.785186 3.448584 0.105833
-0.785538 3.451263 0.103506
-0.785868 3.453785 0.101314
-0.786180 3.456160 0.099250
-0.786473 3.458397 0.097307
-0.786750 3.460504 0.095477
-0.787010 3.462487 0.093753
-0.787255 3.464355 0.092131
-0.787485 3.466114 0.090602
-0.787702 3.467770 0.089163
-0.787907 3.469329 0.087808
-0.788100 3.470798 0.086532
-0.788281 3.472181 0.085331
-0.788452 3.473483 0.084199
-0.788613 3.474709 0.083134
-0.788764 3.475864 0.082131
-0.788907 3.476952 0.081186
-0.789041 3.477976 0.080296
-0.789167 3.478940 0.079458
-0.789286 3.479848 0.078669
-0.789399 3.480703 0.077926
-0.789504 3.481508 0.077227
-0.789604 3.482266 0.076568
-0.789697 3.482980 0.075948
-0.789785 3.483652 0.075364
-0.789868 3.484286 0.074814
-0.789947 3.484882 0.074296
-0.790020 3.485443 0.073808
-0.790090 3.485972 0.073349
-0.790155 3.486470 0.072916
-0.790216 3.486938 0.072509
-0.790274 3.487380 0.072125
-0.790329 3.487795 0.071764