2

I'm trying to create a sparse matrix that has non-numeric elements.

syms a b c;

i = [1 1 2 2];
j = [1 2 1 2];
s = [a b 3 c];

sparse(i,j,s,2,2)

which returns this error:

Undefined function 'sparse' for input arguments of type 'sym'.

Error in Test2 (line 8)
sparse(i,j,s,2,2)

6
  • 1
    Additionally, this is not a sparse matrix. A sparse matrix only makes sense if you have many zero elements. You have none. Commented Feb 8, 2016 at 19:56
  • 1
    There is no such thing as a sparse symbolic matrix in Matlab. You can convert a sparse (numeric) matrix to symbolic but not the other way around. Commented Feb 8, 2016 at 20:02
  • 1
    Sparse and symbolic very rarely have to be in the same sentence. Commented Feb 8, 2016 at 20:02
  • 1
    @AndrasDeak, how about the commonly used sentence: "Although the population is sparse, they can all recite the same highly symbolic poem by heart." Commented Feb 8, 2016 at 20:18
  • 1
    @StewieGriffin you're free to flag my comment if its bluntness offends you;) Commented Feb 8, 2016 at 20:19

3 Answers 3

3

As I stated in the comments, there is no such thing as a sparse symbolic matrix in Matlab. This is stated in the documentation for the third input argument for the form of sparse you're using:

v — Values
scalar | vector | matrix

...

Data Types: double | logical

Matlab's Symbolic Math (and MuPAD) may take advantage of inherent sparsity internally (for storage and computation).

Sign up to request clarification or add additional context in comments.

Comments

1

It's pretty simple: Matlab has no function sparse() that takes symbolic variables as arguments. (s is your problem) The only sparse() function takes just numeric elements.

Comments

0

@horchler is correct that more recent versions of Matlab do not support using the sparse command on symbolic matrices. However, older versions of Matlab allowed this (I tried R2011b and it works there). Thus, you may encounter legacy code that produces the above mentioned error. In this case, you may have to remove the sparse commands manually.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.