Extracting numeric values from symbolic variables
66 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ali akbar
el 6 de Sept. de 2020
Respondida: Alphonce Owayo
el 23 de Feb. de 2021
I have two matrices say
x=[2 4 9 10];
syms c [1 4];
x==c
it returns
2=c1
4=c2
9=c3
10=c4
However when I write c1 in command window, it returns symbolic 'c1'.
I wanted to extract these numeric values or assign these values to c vector. How one would go around this.
0 comentarios
Respuesta aceptada
Thiago Henrique Gomes Lobato
el 6 de Sept. de 2020
Editada: Thiago Henrique Gomes Lobato
el 6 de Sept. de 2020
x==c
The "==" operator is normally used as a logic comparison operation, not an assignment. In the case of using symbolic variables, "==" defines an equation, which could be solved, for example, with the matlab function solve. If you want to give values to your variables, use only one "=" sign, for example:
x=[2 4 9 10];
syms c [1 4];
>> c(1) = 2
c =
[ 2, c2, c3, c4]
>> c=x
c =
2 4 9 10
2 comentarios
madhan ravi
el 6 de Sept. de 2020
“ is a logic operation”. Not in this case when it contains a symbolic variables it forms an equation.
Thiago Henrique Gomes Lobato
el 6 de Sept. de 2020
You're right, it becomes an equation when it contain symbolic variables. Since I believe he was knew to matlab I thought the more general definition of the operator would be easier to understand/apply to future cases. I will edit the answer accordingly
Más respuestas (3)
madhan ravi
el 6 de Sept. de 2020
== forms an equation , it DOESN’T assign any values.
1 comentario
madhan ravi
el 6 de Sept. de 2020
Editada: madhan ravi
el 6 de Sept. de 2020
I would suggest you to do the below instead:
c = num2cell(x);
celldisp(c)
Alphonce Owayo
el 23 de Feb. de 2021
For example;
syms x y
eqn1=x+y==20;
eqn2=2.3x-9y==13;
soln=vpasolve(eqn1,eqn2);
xsoln=soln.x;
ysoln=soln.y;
or
xsoln=double(soln.x);
ysoln=double(son.y);
disp(xsoln);
disp(ysoln);
0 comentarios
Alphonce Owayo
el 23 de Feb. de 2021
shown above is how to extract numeric values from symbolic variables and display them in the command window.
0 comentarios
Ver también
Categorías
Más información sobre Assumptions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!