Borrar filtros
Borrar filtros

how can I convert the output of solve function into matrix form?

9 visualizaciones (últimos 30 días)
Yunus OZCELIK
Yunus OZCELIK el 29 de Oct. de 2016
Comentada: Yunus OZCELIK el 29 de Oct. de 2016
I would like to ask you a question about how to convert the output of solve function into matrix form. As far as I know, the output of solve function is structure. Here is my simple case;
syms x y
k(1,1)=x-6*y-15;
k(1,2)=x+4*y-6;
roots=solve(k==0)
The output is as follows;
roots =
x: [2x1 sym]
y: [2x1 sym]
I know I can call the roots by roots.x and roots.y. However, I will write parametric code with user defined number of equation. So, How can I store those roots into a matrix so that I can use for other operation?

Respuestas (1)

Sophie
Sophie el 29 de Oct. de 2016
Maybe better option is to use linsolve if the system of equations is linear. So that U'll obtain result as matrix. Also you can try smth like this.
c=struct2cell(roots.x);
m=cat(1,c{:});
disp(m);
  1 comentario
Yunus OZCELIK
Yunus OZCELIK el 29 de Oct. de 2016
Sophie, thank you for quick answer. The system of equations are nonlinear. However, your recommendation solved my problem. I changed only first row of your code. Thank you!
c=struct2cell(roots);
m=cat(1,c{:});
disp(m);

Iniciar sesión para comentar.

Categorías

Más información sobre Numbers and Precision 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!

Translated by