Symbolic expressions inside of array

1 view (last 30 days)
syms x
f(x) = x^2;
g(x) = x^3;
a = [f,g];
Imagine I have a code like this, and I wish to evaluate only f for a certain value, but not bring outside of the array. How can I do this? For instance, if now ask for a(3), matlab will output [9,27]. However, I want only want 9.

Accepted Answer

David Hill
David Hill on 14 Apr 2021
syms x y
f = x^2;
g = y^3;
a = [f,g];
subs(a,x,3);
  2 Comments
Bram van Eijnatten
Bram van Eijnatten on 14 Apr 2021
You answer gives me the output [9, y^3], whereas I want merely 9
Bram van Eijnatten
Bram van Eijnatten on 14 Apr 2021
Never mind subs(a(1),x,3) gives the answer, thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!