MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Zero times a variable in numerical calculations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68417] Re: Zero times a variable in numerical calculations
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Fri, 4 Aug 2006 03:59:33 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 8/3/06 at 6:07 AM, Haverkort at ph2.uni-koeln.de (Maurits Haverkort)
wrote:

>Chop[0.0 a] indeed works and returns nicely 0 however I still have
>some problems when using this on Sparse Arrays.

>I define: M = SparseArray[{{1, 1} -> a, {2, 2} -> 1.0, {3, 3} ->
>1.0, {2, 3} -> b, {3, 2} -> b, {_, _} -> 0}, {3, 3}];

You don't need the {_,_}->0 part since by default SparseArray assumes all elements not given specific values are 0. However, deleting this won't solve your problem.

<snip>

>Chop[Simplify[Normal[T.M.T]]] does what I want, but does not work
>with sparse arrays and in between all elements become large
>expressions so I run out of memory.

You don't have to convert the SparseArray to normal form in order to use Chop and Simplify. You could use pattern matching to operate directly on the defined elements, i.e.,

In[3]:=
mat = T . M . T /. SparseArray[a_, b_, c_, {x__, y_}] :> 
     SparseArray[a, b, c, {x, Chop[Simplify[y]]}]; 
Normal[mat]

Out[4]=
{{1.*a, 0, 0}, {0, 1.0000000000000002 - 1.0000000000000002*b, 0}, 
  {0, 0, 1.0000000000000002*b + 1.0000000000000002}}

--
To reply via email subtract one hundred and four


  • Prev by Date: Re: How to treat this false singular point?
  • Next by Date: Change CellTags with FrontEnd
  • Previous by thread: Re: Zero times a variable in numerical calculations
  • Next by thread: Re: Zero times a variable in numerical calculations