Consider the script
syms a b;
f = a.*b;
a = [1 2];
b = [0 2];
subs(f)
This yields a vector as output ([0, 4]), but the intended output is a scalar (4), given the element-wise multiplication that should be performed.
How can I properly utilize vectors when substituting symbolic functions?
I believe you're making two mistakes. The first is that you're overwriting your symbolic variables with double arrays, so you're not actually calling
subsfor a symbolic object:The second is that preventing this will still give a wrong answer:
That's because, as you see in the printed version of
f, the symbolic engine treatsaandbas scalars.So to do what you probably want to do you need to define your syms to be 2-element arrays:
But anyway, as you can see, the result is still an array since
.*(or symbolic*) is elementwise multiplication. In order to get a scalar product, usesym/dot: