MATLAB: Element wise substitution of variable array in array of equations (of same length)

arrayelementwisesubs

Hi,
I want to substitute the values of a 1×17 vector in a 1×17 symbolic vector of equations. Which should give me a 1×17 vector as a result. However, in any way that I tried with the matlab command 'subs', the substitution is done for every value in every equation which gives 17 times 17 values. Which is way to much. I also don't want to work with a for-loop since it extremely slows down the script. Can anyone help me with this?

Best Answer

There is no way to do that in the Symbolic Math toolbox. You need a loop at some level, whether you code it yourself or use arrayfun() to hide the loop (note: until R2017b, arrayfun() requires 'uniform', 0 for symbolic results.)
The proper way to code for this would be to use independent variables
x = sym('x', [1 2])
eq = [x(1), x(2)+2];
val = [1, 2];
subs(eq, x, val)