Azzera filtri
Azzera filtri

Assigning a symbolic value in a vector

10 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 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 Commenti
Sebastian Daneli
Sebastian Daneli il 3 Nov 2019
Gonna see if there is a better way to keep track on the vectors in the link you posted

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Tag

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by