Is it possible to hold symvars, if the value is 0?

Hi all,
I’ve a question concerning the symbolic package.
With the function_handle -function it’s possible to transfer a symbolic function into
a usual octave-function.

Suppose a vectorfunction like


there are no problems:


But supposing the symfcn


the function_handle gives


So it leads to an error if calling f(1:10), 'cause the dim varies.
I can’t believe, that there is no solution to this problem.

I’ve make a scary workaround: If there a out-dim without a domain-var, i added sym(1)/10^15 to the vectorfunction. It’s not just scary, but also change the functionresult too.

I can change to functions like:


whats lead to


but thats no Option for my purpose.

Any suggestions?

Today, i’m happy of a solution i’ve found.
I turn the arrayfcn into a cellfcn:

    f_h_Cell=@(x, y) {x .* y, 0}
   nf = @(x) @mifCell2Mat (f_h_Cell (x (size (x) (1) * 0 / 2 + 1:size (x) (1) * 1 / 2,{':'} (ones (1, ndims (x) - 1)){:}), x (size (x) (1) * 1 / 2 + 1:size (x) (1) * 2 / 2, {':'} (ones (1, ndims (x) - 1)) {:})))

and then:

function res=mifCell2Mat(resCell)
  resCell=cellfun(@(x) x+zeros(refSize),resCell,'uniformoutput',false);

All automate calling following function

so a simple[x;y;z]) call gives the result.

Of course it doesn’t work, if there are numel’s between 1 and say size=[10,10] of
eg size=[10,1], but so what … In most cases it work’s for me (until now: allways).

Oh, while i read my code just here, i’ve found a little bug:


must of course change to


cause there a possible more than one max sizes in the idx, so i’ve picked the first. I do first a test of constant outDims, so that these workaround only occours, if there are constants. In the other cases (if all outDims contain domainvars) a simple anonymous function of a matrix-handle appears to the user:

f_h_Mat=@(x, y) [x .* y; x]

nf=@(x) f_h_Mat (x (size (x) (1) * 0 / 2 + 1:size (x) (1) * 1 / 2, {':'} (ones (1, ndims (x) - 1)) {:}), x (size
(x) (1) * 1 / 2 + 1:size (x) (1) * 2 / 2, {':'} (ones (1, ndims (x) - 1)) {:}))

A warning appears because the function_handle - function gets a ‘cell’ class instead of a ‘sym’:

warning: expected output expressions to be syms
warning: called from
    codegen>codegen_input_parser at line 184 column 7
    codegen at line 21 column 40
    function_handle at line 94 column 14

You can supress this with:

warning('off', 'expected output expressions to be syms');

Edit: Should work, but does not.
also gives no id
With id, you can suppress warnings with

All of the tests i made suggests that there is no really problem regarding this warning.

I don’t have any suggestions to add here. It’s true that what you want to do doesn’t seem to work correctly, but that just looks like a limitation of converting between symbolic expressions and vectorized expressions.

If your second comment is a solution to the problem, you can mark it as a solution for this topic.