简体   繁体   中英

Undefined function 'sparse' for input arguments of type 'sym'. (Matlab)

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)

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).

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.

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM