Filter löschen
Filter löschen

Assigning a symbolic value in a vector

10 Ansichten (letzte 30 Tage)
Sebastian Daneli
Sebastian Daneli am 3 Nov. 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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 3 Nov. 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 Kommentare
Walter Roberson
Walter Roberson am 3 Nov. 2019
subs(Xb, x, [0, 1, 13])
Sebastian Daneli
Sebastian Daneli am 3 Nov. 2019
Gonna see if there is a better way to keep track on the vectors in the link you posted

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by