Borrar filtros
Borrar filtros

Assigning a symbolic value in a vector

10 visualizaciones (últimos 30 días)
Sebastian Daneli
Sebastian Daneli el 3 de Nov. de 2019
Comentada: Sebastian Daneli el 3 de Nov. de 2019
I have a vector with symbolic variables, x=[x1 x2]. Now I need to assign alues to these variables, not to the positions in the matrix.
I want to assign x1 with, say 1, and have x1=1, not x=[1 x2]. So I need to extract the variables from the matrix, and then assign them, it that makes any sense.

Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Nov. de 2019
That is possible, but not recommended.
My experience suggests that it is nearly always a bad idea to assign a definite value to a symbolic variable after the variable has been used in an expression, except possibly when you are going to overwrite that other expression (and everythign derived from it.) There gets to be too much confusion about whether the name should represent the unresolved variable or should represent the replacement. For example,
syms x
y = x^2
x = 1
symvar(y)
will show x, and if you display x you will get 1, but y is not 1^2, it is symbolic-x squared, with there being no connection between the symbolic-x and the x you assigned numeric 1 to.
In nearly every case, it is better to use subs(), such as
syms x
y = x^2
xvals = 1
subs(y, x, xvals)
  2 comentarios
Walter Roberson
Walter Roberson el 3 de Nov. de 2019
subs(Xb, x, [0, 1, 13])
Sebastian Daneli
Sebastian Daneli el 3 de Nov. de 2019
Gonna see if there is a better way to keep track on the vectors in the link you posted

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by