How to convert solution of syms array to a normal array?
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
wei zhang
el 3 de Jun. de 2020
Comentada: wei zhang
el 3 de Jun. de 2020
I am solving a series function, e.g.
. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/308855/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/308852/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/308855/image.png)
I want to get the
obviously.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/308858/image.png)
For my codes,
b = 2;
y = [1,2,3,4];
syms x [1 4]
S = solve(dot(repmat([a,b],4,1),[x;y].',2)==0);
The answer is
S =
struct with fields:
x1: [1×1 sym]
x2: [1×1 sym]
x3: [1×1 sym]
x4: [1×1 sym]
All I want is an array of [-2,-4,-6,-8]. How to get the array from this 'S' syms struct. Is there other better ways to solve this problem. The example function is a simple one. So it is impossible for me to use 'x = -1/a*b*y'.
0 comentarios
Respuesta aceptada
KSSV
el 3 de Jun. de 2020
Read about double.
syms x y
a = 1 ; b = 2 ;
eqn = a*x+b*y==0 ;
sol = solve(eqn,x) ;
%
y = [1 2 3 4] ;
iwant = double(subs(sol,y))
Más respuestas (0)
Ver también
Categorías
Más información sobre Symbolic Math Toolbox 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!