How to get vector output from solve?

16 views (last 30 days)
Standardtrickyness
Standardtrickyness on 27 Aug 2017
Commented: Walter Roberson on 30 Aug 2017
How to get vector output from solve? When I do something like y=solve( I*x == zeros(n,1) , x ); (n moderately large) I can get values y.x1 etc but I want to get the entire vector of x. Also if anyone knows the best way to get binary solutions I'm currently involving x.*x =x in the set of equations but this seems potentially inefficient.
p.s to any mathworks staff I think the documentation for solve could really be improved with references to syms and sym as well as explicitly stating that you can do two sets of equations by putting a comma in between
  2 Comments
Karan Gill
Karan Gill on 29 Aug 2017
Thanks for the doc feedback.
What problem did you run into with syms and sym? By reference, do you mean a link? syms or sym can be found via a Google search or documentation search.
Why do you prefer entering equations with commas instead of using an array?
Karan (Symbolic doc)
Walter Roberson
Walter Roberson on 30 Aug 2017
The "See also" at the bottom of the "solve" doc does not list syms or sym

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 27 Aug 2017
X = cell(size(x));
[X{:}] = solve(I*x == zeros(n,1) , x)
"as well as explicitly stating that you can do two sets of equations by putting a comma in between"
Historically that was documented up to R2012a, in which release using a vector or array of equations was not documented or was not permitted. The documentation since then has not been clear as to whether multiple equations are permitted outside of a vector or array of equations; I have formed the impression that they intend to discourage lists of equations.
"Also if anyone knows the best way to get binary solutions"
I recommend not using solve() for this purpose unless you need to work with symbolic values. If your arrays can be reduced to numeric values, I recommend looking at https://www.mathworks.com/matlabcentral/answers/16192-inversion-of-a-boolean-matrix
For symbolics, you could experiment with using
assume(in(x,'integer') & x>=0 & x<=1)
however, in general the inverse would not be binary.
For more robust symbolics, you could wander into MuPAD Galois Fields. You will need to use evalin(symengine) or feval(symengine) in order to create these objects.
  10 Comments
Standardtrickyness
Standardtrickyness on 29 Aug 2017
Sorry I wrote I*x=1 instead of I*x=0 x still confined to be 0,1 I don't know what you mean by solutions to I^m indexed at (J,K) ~= 0 I is not square so I^m does not make sense.
Walter Roberson
Walter Roberson on 29 Aug 2017
Do not use incidence matrices for this purposes: use a square adjacency matrix.
If you have an adjacency matrix, A, then the places where A^1 is non-zero tell you all the places that can be reached from somewhere after 1 step, and the places where A^2 is non-zero tell you all the places that can be reached from somewhere after 2 steps, and so on.
If you take B = A^n for some integer n, and B(J,J) is non-zero, then if you started at node J at the beginning and you took n steps, then you were able to reach node J after n steps -- indicating that node J is part of a cycle that is n steps long. The cycle might have been repeated several times, so possibly the smallest cycle from J was any of the prime factors of n long.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!