All pastes #800502 Raw Edit

Something

public text v1 · immutable
#800502 ·published 2007-11-28 14:30 UTC
rendered paste body
f = @(x) x.^5;
n = 5;

matrix = ones(5)
for i=0:n
  tarray(i+1) = i/n;
end
for j=1:(n+1)
   for i=1:(n+1)

       matrix(j,i) = tarray(i).^(j-1);
   end
end

matrixanswer = [0 0 0 0 0];
for i=1:(n+1)
    matrixanswer(i) = f(tarray(i));
end
matrixanswer
matrixanswer = matrixanswer';
c = cond(matrix);
solution = matrix\matrixanswer;
residualvector = (matrix*solution) - matrixanswer;

fprintf('The Condition of the Row-Based N=5 matrix is %2.5f and the solution is\n', c);
solution
fprintf('And the Residual Vector is \n');
residualvector

matrixanswer = [0 0 0 0 0];
for i=1:(n+1)

   for j=1:(n+1)

       matrix(i,j) = tarray(i).^(j-1);

   end

end
for i=1:(n+1)

    matrixanswer(i) = f(tarray(i));

end
matrixanswer = matrixanswer';
c = cond(matrix);
solution = matrix\matrixanswer;
residualvector = (matrix*solution) - matrixanswer;
fprintf('The Condition of the Column-Based N=5 matrix is %2.5f and the solution is\n', c);
solution
fprintf('And the Residual Vector is \n');
residualvector

% The Condition of the Row-Based N=5 matrix is 4924.37106 and the solution is
% 
% solution =
% 
%    -6.8503
%    37.8620
%   -84.0653
%    93.6480
%   -52.2980
%    11.7037
% 
% And the Residual Vector is 
% 
% residualvector =
% 
%   1.0e-014 *
% 
%     0.1776
%     0.0320
%     0.1357
%    -0.3927
%     0.0777
%     0.1776
% 
% The Condition of the Column-Based N=5 matrix is 4924.37106 and the solution is
% 
% solution =
% 
%      0
%      0
%      0
%      0
%      0
%      1
% 
% And the Residual Vector is 
% 
% residualvector =
% 
%      0
%      0
%      0
%      0
%      0
%      0

f = @(x) x.^5;
n = 30;

matrix = ones(30)
matrixanswer = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
for i=0:n
  tarray(i+1) = i/n;
end
for j=1:(n+1)
   for i=1:(n+1)

       matrix(j,i) = tarray(i).^(j-1);
   end
end
for i=1:(n+1)
    matrixanswer(i) = f(tarray(i));
end
matrixanswer;
matrixanswer = matrixanswer';
c = cond(matrix);
solution = matrix\matrixanswer;
residualvector = (matrix*solution) - matrixanswer;

fprintf('The Condition of the Row-Based N=30 matrix is %2.5f and the solution is\n', c);
solution
fprintf('And the Residual Vector is \n');
residualvector

matrixanswer = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
for i=1:(n+1)

   for j=1:(n+1)

       matrix(i,j) = tarray(i).^(j-1);

   end

end
for i=1:(n+1)

    matrixanswer(i) = f(tarray(i));

end
matrixanswer = matrixanswer';
c = cond(matrix);
solution = matrix\matrixanswer;
residualvector = (matrix*solution) - matrixanswer;
fprintf('The Condition of the Column-Based N = 30 matrix is %2.5f and the solution is\n', c);
solution
fprintf('And the Residual Vector is \n');
residualvector

% The Condition of the Row-Based N=30 matrix is 2459531274782167600.00000 and the solution is
% solution =
%   1.0e+010 *
%    -0.0000
%     0.0001
%    -0.0006
%     0.0040
%    -0.0198
%     0.0739
%    -0.2194
%     0.5295
%    -1.0558
%     1.7586
%    -2.4620
%     2.9059
%    -2.8912
%     2.4192
%    -1.6980
%     1.0041
%    -0.5167
%     0.2563
%    -0.1431
%     0.0910
%    -0.0558
%     0.0284
%    -0.0109
%     0.0027
%    -0.0002
%    -0.0002
%     0.0001
%    -0.0000
%     0.0000
%    -0.0000
%     0.0000
% And the Residual Vector is 
% residualvector =
%   1.0e-006 *
%     0.0123
%    -0.0347
%    -0.3498
%     0.7121
%     0.1050
%     0.0210
%    -0.0416
%     0.0196
%     0.0092
%     0.0151
%     0.0095
%     0.0016
%    -0.0010
%     0.0003
%     0.0002
%     0.0001
%     0.0000
%     0.0001
%     0.0001
%     0.0002
%     0.0001
%    -0.0000
%    -0.0000
%     0.0000
%     0.0000
%    -0.0000
%     0.0000
%    -0.0000
%     0.0000
%     0.0000
%     0.0000
% Warning: Matrix is close to singular or badly scaled.
%          Results may be inaccurate. RCOND = 1.647133e-020.
% > In interpolate at 144
% The Condition of the Column-Based N = 30 matrix is 3381333759104609300.00000 and the solution is
% solution =
%          0
%     0.0000
%    -0.0000
%     0.0000
%    -0.0000
%     1.0000
%    -0.0000
%     0.0000
%    -0.0001
%     0.0004
%    -0.0014
%     0.0040
%    -0.0085
%     0.0124
%    -0.0097
%    -0.0036
%     0.0180
%    -0.0142
%    -0.0103
%     0.0256
%    -0.0049
%    -0.0301
%     0.0341
%    -0.0054
%    -0.0142
%     0.0049
%     0.0117
%    -0.0146
%     0.0078
%    -0.0021
%     0.0002
% And the Residual Vector is 
% residualvector =
%   1.0e-015 *
%          0
%    -0.0326
%    -0.0595
%    -0.0901
%    -0.1109
%    -0.1323
%    -0.1501
%    -0.1647
%    -0.1778
%    -0.1913
%    -0.2047
%    -0.2177
%    -0.2220
%    -0.2325
%    -0.2429
%    -0.2325
%    -0.2429
%    -0.2429
%    -0.2776
%    -0.2637
%    -0.2498
%    -0.1943
%    -0.3331
%    -0.3886
%    -0.1665
%    -0.2776
%    -0.1110
%    -0.1110
%    -0.3331
%    -0.3331
%    -0.2220
% 
% 
%