Matrix is close to singular or badly scaled. HELP!

Hello guys, I am new here, I am doing some project on interpolation and approximation. I have been given values for x and y, now I have to get the polynomials for them. I've done something, but the values of coefficients for approximation and those for interpolation are totally different, so something's wrong. Can someone just help me? Here is what I did till now:
% APPROXIMATION
%________________________________________________________________________
format long g;
% Input values for x and y
x1 = 0.131568108472; y1 = 258.433497034; x2 = 0.199557064651; y2 = 94.8235556162; x3 = 0.596426092301; y3 = 46.4773492701; x4 = 10.1301082178; y4 = 4.40548687035; x5 = 350.467757284; y5 = 0.770454788749; x6 = 1271.93067998; y6 = 0.468660756742; x7 = 12162.8432144; y7 = 0.409611101849; x8 = 59113.7385534; y8 = 0.458959722808; x9 = 287130.854195; y9 = 0.414685133805;
%Matrix form of approximation % A * x = b;
b = [y1; y2; y3; y4; y5; y6; y7; y8; y9];
v1 = [x1^2, x1, 1]; v2 = [x2^2, x2, 1]; v3 = [x3^2, x3, 1]; v4 = [x4^2, x4, 1]; v5 = [x5^2, x5, 1]; v6 = [x6^2, x6, 1]; v7 = [x7^2, x7, 1]; v8 = [x8^2, x8, 1]; v9 = [x9^2, x9, 1];
A = [v1;v2;v3;v4;v5;v6;v7;v8;v9]; %Augmented matrix:
AugA = A'*A;
Augy = A'*b;
%
x = inv(AugA)*Augy; % the coefficients of the quadratic equation
a = x(1); b = x(2); c = x(3); %approximated_function = a*x^2 + b*x + c;
%________________________________________________________________________
% INTERPOLATION
x = [x1, x2, x3, x4, x5, x6, x7, x8, x9]; y = [y1, y2, y3, y4, y5, y6, y7, y8, x9];
Dy(1) = (y(2)-y(1))/(x(2)-x(1)); Dy(2) = (y(3)-y(2))/(x(3)-x(2));
Dy2(1) = (Dy(2) - Dy(1))/(x(3)-x(1));
a1 = y1; a2 = Dy(1); a3 = Dy2(1);
a, b, and c are coefficients for approximation a1, a2, a3 are those for interpolation
Why are they so different, I think something is wrong with approximation as MATLAB gives me info on error:
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 9.495734e-022. > In approximation at 43

Answers (1)

range(AugA(:))
You'll see that the difference is on the order of 10^21. Double precision floating point values only have an accurate range of 16 decimal digits.
You'll need to either:
  • use the symbolic toolbox
  • use John's vpi (variable precision integers (constrained to integers only))
  • reformat your problem

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Asked:

on 1 Apr 2011

Community Treasure Hunt

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

Start Hunting!