Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.3K Views
|
6 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Function based on Sparsearray with variable

Posted 2 years ago

Hello, I defined a function using sparsearray with a variable. it was working with previous version of Mathematica but does not work with mathematica13.2. The variable (x) inside sparsearray can not anymore become the variable of my function f[x]. See below when I write f[y], I get f[x]. What can I do to have x as variable ?
Thanks for your help.

POSTED BY: Marie-Anne Arrio
6 Replies

I have seen that SparseArray does not work well with Simplify, and I presume also with other functions. In your case I would use either Normal[SparseArray[]] or DiagonalMatrix.

By the way, I suspect that f[x_] := Evaluate[CF] is equivalent to f[x_] = CF. Does anyone know for sure?

POSTED BY: Gianluca Gorni
Posted 2 years ago

I can't speak to whether this is an intentional change in behavior. However, I would suggest that this manner of defining things is fraught. I actually wouldn't have expected SparseArray to work as a sort of "template" anyway--it's a special wrapper to represent a data structure with certain optimizations, and so I would expect to be rather opaque.

But there is probably a better way to get what you want. If you could provide some context for how you're defining CF and the various things that it depends on, then it would be easier to describe an alternate approach. In the meantime one thing you could try is to create all of the structure without actually applying SparseArray until the very last step.

POSTED BY: Eric Rimbey

There is something anomalous in your code. If I evaluate Normal[CF] I get a matrix with mysterious variables Dss and Dtt:

{{2 Dss - Dtt, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 2 Dss - Dtt, 0, 0, 0, 
  0, 0, 0, 0, 0}, {0, 0, -Dss + 4 Dtt, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 
  0, -Dss + 4 Dtt, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, -2 Dss - 6 Dtt, 0, 
  0, 0, 0, 0}, {0, 0, 0, 0, 0, -2 Dss - 6 Dtt, 0, 0, 0, 0}, {0, 0, 0, 
  0, 0, 0, -Dss + 4 Dtt, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, -Dss + 4 Dtt,
   0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 2 Dss - Dtt, 0}, {0, 0, 0, 0, 0, 0,
   0, 0, 0, 2 Dss - Dtt}}

Similarly with InputForm[CF].

I think you should talk with your collaborator.

POSTED BY: Gianluca Gorni

The SparseArray (CF) comes from another function created by my collaborator and I can not change it (I will talk to him). As suggested by Gianluca Goring (see discussion), I had to use Evaluate[Normal[CF]], Normal[] being not sufficient. The question remains why it was working in previous version... Thanks for your help

POSTED BY: Marie-Anne Arrio

Thanks for your help. Yes, I succeeded using Evaluate[Normal[CF]]. Normal[CF] does not work. I have now to change all my old notebooks... :/ Something might have change in the last mathematica version....

POSTED BY: Marie-Anne Arrio

The following inputs all give True:

AtomQ[CF]
FreeQ[CF, x]
D[CF, x] == Table[0, {10}, {10}]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard