Symbolic expressions inside of array

3 visualizaciones (últimos 30 días)
Bram van Eijnatten
Bram van Eijnatten el 14 de Abr. de 2021
Comentada: Bram van Eijnatten el 14 de Abr. de 2021
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.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by