Evaluating symbolic function with a vector
Show older comments
I know this has been asked before, but none of the answers I've found have been helpful.
Here's the simple example of what I'm trying to do:
syms x1 x2
f(x1,x2) = x1 + x2;
x = [ 1 1];
f(x)
I would expect this to return:
ans =
2
Which, of course, is not working, as seen in the error stated above.
Any insights on how can I define a function that accepts a vector of values for many variables?
Accepted Answer
More Answers (1)
% take x1 and x2 as two variables
syms x1 x2
f(x1,x2) = x1 + x2;
x = [ 1 1];
f(x(1), x(2))
Categories
Find more on Operations on Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!