Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6880
| From | Leonid Shifrin <lshifr@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: gives different result compared to 1/Diagonal[Normal@A] when A is sparse |
| Date | 2011-12-01 12:28 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jb7rtd$j3d$1@smc.vnet.net> (permalink) |
I think this is the same bug as discussed in this thread:
http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_thread/thread/37935f55b291ed2
where in my answer there I also indicated what the origin of that behavior
might be.
Cheers,
Leonid
On Wed, Nov 30, 2011 at 3:50 PM, Oliver Ruebenkoenig
<ruebenko@wolfram.com>wrote:
>
>
> I filed this as a bug.
>
> One small side note: You might want to use
>
> A[[r, r + 1]] = 0.;
> A[[r + 1, r]] = 0.;
>
> instead of A[[..]]=0.& /@ r. Extraction/Setting of SA componets is
> vectoriezed.
>
> Oliver
>
> On Wed, 30 Nov 2011, Nasser M. Abbasi wrote:
>
> > I found this strange behavior, and I do not think it is correct.
> >
> > This is version 8.04.
> >
> > 1/Diagonal[A] gives a divide by zero error, but 1/Diagonal[Normal@A]
> does
> > not. This is when A is sparse.
> >
> > ------------------------------
> > Clear["Global`*"]
> >
> > makeMatrix[n_]:=Module[{numberOfUnknowns=n^2,r,A},
> >
> > A=SparseArray[
> > {
> > Band[{1,1}]->4.0,
> > Band[{2,1}]->-1,
> > Band[{1,2}]->-1,
> > Band[{1,n+1}]->-1,
> > Band[{n+1,1}]->-1
> > },{numberOfUnknowns,numberOfUnknowns},0.
> > ];
> >
> > r=Range[n,n^2-n,n];
> > (A[[#,#+1]]=0.)&/@r;
> > (A[[#+1,#]]=0.)&/@r;
> >
> > A
> > ];
> >
> > (A = makeMatrix[3])//MatrixForm
> >
> > (Diagonal[A])//Normal
> >
> > 1/Diagonal[Normal@A] (* ===> OK *)
> > 1/Diagonal[A] (* error *)
> >
> > ----------------------------------------
> >
> > So, 1/Diagonal[Normal@A] gives
> > {0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25}
> >
> > but 1/Diagonal[A] gives 1/0
> >
> > In another system I use, both operations give
> > {0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25,0.25}
> >
> > i.e. if the matrix is sparse or not, 1/Diagonal[A] should work
> > regardless. I think sparse matrices need to be more integrated into
> > all Mathemaitca matrix operations.
> >
> > Or Am I missing something here?
> >
> > Thanks,
> > --Nasser
> >
> >
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: gives different result compared to 1/Diagonal[Normal@A] when A is sparse Leonid Shifrin <lshifr@gmail.com> - 2011-12-01 12:28 +0000
csiph-web