I am trying to evaluate a MatlabFunction with a single vector, meaning that this vector would hold a value for each variable in that MatlabFunction.
To use a simple example, I can define a MatlabFunction as such :
syms x [3 1];
f1 = matlabFunction((x1 + x2)*x3, 'var', sym2cell(x));
This defines a symbolic variable x
that holds three symbolic variables : x1 x2 x3
and a MatlabFunction equals to @(x1,x2,x3)x3.*(x1+x2)
I am able to calculate the gradiant of f1
on point a
with :
a = [1; 0; 0];
gradf = gradient(mf, x);
gradiant_of_a = double(subs(graf, x, a));
What bothers me is that I cannot do the same for :
f1_of_a = double(subs(f1, x, a));
I've seen that subs
won't work on function handle. But it does on symbolic objects, which gradf
is for example.
Is there any solution to this problem ?
I found answers telling to go with f1_of_a = f1(1, 0, 0);
, but this doesn't suits me since I am using MatlabFunctions with an unknown number of variable. (size of x
and a
could be (1, 3), or (1, 10) and should still work for example, and I won't be typing by hand the 10 arguments in the second case)
Thank you for any help about this !