Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
LARGE roundoff error in matrix-vector multiplication?

Subject: LARGE roundoff error in matrix-vector multiplication?

From: Henry Wolkowicz

Date: 5 Nov, 2010 20:40:05

Message: 1 of 2

I get the following relatively large roundoff error on matrix-vector multiplication

>> [size(A) nnz(A) nnz(x) normest(round(A*1e3)/1e3-A)]
ans =
   129 185 465 185 0
>> norm(A(:,colPerm)*x(colPerm) - A*x)
ans =
  1.3523e-012

i.e. a A is sparse 129by185 and I am finding A*x
A has numbers with 2 decimal accuracy. The vector colPerm is a permutation of the integers 1:185. By permuting the columns of A and components of x and redoing the multiplication I get an error in the 12th place. This seems like an enormous error for this type of multiplication. This does not happen with random matrices A. So perhaps there is some catastrophic 'subtraction' roundoff that happens? But getting an error in the 12th place seems enormous to me. I am trying to obtain a high accuracy algorithm and this is just checking the error at the end. So the error check has an error in it?
Am I doing something wrong here?

Subject: LARGE roundoff error in matrix-vector multiplication?

From: Henry Wolkowicz

Date: 5 Nov, 2010 21:25:06

Message: 2 of 2

Here is a follow up:
If I just use one row of the matrix (which only has 6 nonzero elements), then
I still get an error in the 13th place by changing the order of the arithmetic.
It seems that 'catastrophic subtraction error' is what is going on?

here is the input

format long
full([tempA tempx tempAperm tempxperm])
valrow3=tempA'*tempx
valrow3perm=tempAperm'*tempxperm
valrow3perm- valrow3

and here is the output
 1.0e+003 *
   0.001000000000000 0.000000000000000 0.001000000000000 0.000000000000000
  -0.000400000000000 0.158000000000000 -0.001700000000000 0.158000000000000
  -0.000400000000000 0.158000000000000 0.001500000000000 2.504373333333334
   0.001500000000000 2.504373333333334 -0.000400000000000 0.158000000000000
  -0.001700000000000 0.158000000000000 -0.000400000000000 0.158000000000000
  -0.001700000000000 0.158000000000000 -0.001700000000000 0.158000000000000


valrow3 =
    3.092960000000001e+003
valrow3perm =
   3.092960000000001e+003
ans =
   4.547473508864641e-013

-----------------------------------------------------------------------------------------
"Henry Wolkowicz" <hwolkowicz@uwaterloo.ca> wrote in message <ib1q35$8rp$1@fred.mathworks.com>...
> I get the following relatively large roundoff error on matrix-vector multiplication
>
> >> [size(A) nnz(A) nnz(x) normest(round(A*1e3)/1e3-A)]
> ans =
> 129 185 465 185 0
> >> norm(A(:,colPerm)*x(colPerm) - A*x)
> ans =
> 1.3523e-012
>
> i.e. a A is sparse 129by185 and I am finding A*x
> A has numbers with 2 decimal accuracy. The vector colPerm is a permutation of the integers 1:185. By permuting the columns of A and components of x and redoing the multiplication I get an error in the 12th place. This seems like an enormous error for this type of multiplication. This does not happen with random matrices A. So perhaps there is some catastrophic 'subtraction' roundoff that happens? But getting an error in the 12th place seems enormous to me. I am trying to obtain a high accuracy algorithm and this is just checking the error at the end. So the error check has an error in it?
> Am I doing something wrong here?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us