Every time I run this, I'm getting the error that my random matrix is poorly conditioned. It's weird because I don't get the same error if I just create one in the command window.(adsbygoogle = window.adsbygoogle || []).push({});

My script:

clc

clear all

% part 1

x = rand(20, 1);

save('x.mat', 'x');

a = rand(20, 20);

save('a.mat', 'a');

y = a*x;

c = [a, y];

x1 = diag(rref(c));

x2 = inv(a) * y;

x3 = a\y;

ex1 = norm(x - x1);

ex2 = norm(x - x2);

ex3 = norm(x - x3);

fprintf('Using random matrix: \n \n')

fprintf('Error using rref function: %f \n', ex1)

fprintf('Error using inv function: %f \n', ex2)

fprintf('Error using backslash operator: %f \n', ex3)

clear a y c x1 x2 x3 ex1 ex2 ex3

% part 2

a = hilb(20);

y = a*x;

c = [a, y];

x1 = diag(rref(c));

x2 = inv(a) * y;

x3 = a\y;

ex1 = norm(x - x1);

ex2 = norm(x - x2);

ex3 = norm(x - x3);

fprintf('\n Using hilbert matrix: \n \n')

fprintf('Error using rref function: %f \n', ex1)

fprintf('Error using inv functoin: %f \n', ex2)

fprintf('Error using backslash operator: %f \n', ex3)

Output:

Using random matrix:

Error using rref function: 2.722469

Error using inv function: 0.000000

Error using backslash operator: 0.000000

Warning: Matrix is close to singular or badly scaled. Results

may be inaccurate. RCOND = 1.155429e-19.

> In hw6 at 30

Warning: Matrix is close to singular or badly scaled. Results

may be inaccurate. RCOND = 1.155429e-19.

> In hw6 at 31

Using hilbert matrix:

Error using rref function: 2.745181

Error using inv functoin: 134.434224

Error using backslash operator: 103.192355

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Any idea why I'm ALWAYS getting a nonsingular matrix warning?

Loading...

Similar Threads - idea ALWAYS getting | Date |
---|---|

No idea where to start with this question (very new to matlab): | Feb 14, 2013 |

Probability of False Alarm_A simple idea will do | Mar 21, 2012 |

Mathematica always needs a clean start? | Mar 7, 2012 |

Error on mathlab, and I have no idea how to correct it, please help me out | Feb 8, 2012 |

Any ideas of how to represent a list in pseudo-code in LaTex? | Jul 28, 2011 |

**Physics Forums - The Fusion of Science and Community**