Skip to content

Assigning a symbolic expression to an element of a numerical matrix fails #191

Open
@liondog

Description

@liondog

Once again this is a piece of code that I wrote in MATLAB and failed to execute in Octave with the most recent octsympy. Assume the following code

syms x
x = 2*pi/1853; % arbitrary symbolic expression that only contains symbolic variables that have a 
               % direct numerical equivalent, i.e. x = sym(0.113242); is also fine, or x = sym(e);

If one assigns

y = x;

y will become a symbolic variable, too. But the situation is different for numerical matrices. If you assign x to an arbitrary element of a numerical matrix, MATLAB automatically tries to convert the symbolic expression to a numerical value with the double function and throws an error if it fails ("Error in MuPAD command: DOUBLE cannot convert the input expression into a double array. If the input expression contains a symbolic variable, use the VPA function instead."). For instance

(...)
syms t
y = zeros(1, 2);
y(1, 2) = x; % this works just fine in MATLAB
y(1, 2) = sym(pi*t); % this fails in MATLAB

in MATLAB the next-to-last line works and y is still of type double, in Octave both assignments to y fail with

error: operator =: no conversion for assignment of 'class' to indexed 'matrix'
error: assignment failed, or no method for 'matrix = class'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions