|
"Duc" wrote in message <is0op4$dua$1@newscl01ah.mathworks.com>...
> Hi John,
>
> So sorry for my deficiencies here. My first approach is the full matrix operations, then I switch to sparse matrix. So, it is assumed that K and KK is the same numeric data, but they're the same only few first iterations.
>
> inside a for loop:
> __________________________________________________________________
> k = B_s'*C_shear *B_s*gaussWeights(q)*det(Jacob);
> K = K + sparse(colMap, rowMap,k,GDof,GDof);
> KK(elementDof,elementDof)=KK(elementDof,elementDof)+k;
> ___________________________________________________________________
>
> After the loop, KK - K is not a zero matrix :(
The point is that when you add more than two numbers in
floating point arithmetic, the sequence that you add them
matters.
>> (.3 + .2 + .6) == (.6 + .3 + .2)
ans =
0
There is NO presumption that the sequence of operations
is identical for a sparse versus floating point operation,
nor should you EVER trust the least significant bits of
such an operation.
As I said, welcome to the floating point world.
John
|