How to substitute a vector symbolic variable with the values of a vector?

12 vues (au cours des 30 derniers jours)
Vishnu Narayan Vipin
Vishnu Narayan Vipin le 28 Sep 2018
Modifié(e) : madhan ravi le 29 Sep 2018
x = sym('x',[1 2]).';
Q = [1 0;0 1]
f = x.'*Q*x;
xo = ones(2,1)
fo = (subs(f,{x(1),x(2)},{xo(1),xo(2)}))
x is a symbolic vector of dimension 50. I want to substitute 50 values in xo into each of x1,x2,....x50 in x.
Thanks a lot!

Réponses (1)

madhan ravi
madhan ravi le 28 Sep 2018
Modifié(e) : madhan ravi le 29 Sep 2018
Your code works fine, you can substitute the same way using curly braces. What problem are you facing ?, everything seems to be fine in your code.
subs(f, x, xo) %edited after sir Walter’s comment.
  4 commentaires
Walter Roberson
Walter Roberson le 29 Sep 2018
subs(f, x, xo)
In the case of vector of variables and vector of values the same size, corresponding substitute is done. The {} notation would be needed if at least one of the substitutions was not a scalar.
madhan ravi
madhan ravi le 29 Sep 2018
Thank you @sir Walter

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by