How to make matlab give me a numeric answer to a matrix with infinite solutions
9 次查看(过去 30 天)
显示 更早的评论
So, I have this matrix:
MCh = 1 0 -1 0
5 0 0 -1
0 2 -3 -1
0 1 -4 0
and I'm using \ to solve the system using this other matrix:
B = 0
0
0
0
This is obviously giving me an infinite amount of solutions, so how do I make it give me one of all of the sets?
I am using MCh\B to solve it.
Thanks for the help!
0 个评论
采纳的回答
John D'Errico
2022-3-31
MCh =[ 1 0 -1 0
5 0 0 -1
0 2 -3 -1
0 1 -4 0];
rank(MCh)
You wish to solve the 4x4 homogeneous linear system. It will have a valid non-zero solution only if the rank is less than full rank. Since the rank is 3, it has a solution. The way to solve it is to find the nullspace of the matrix. That is:
format long
X = null(MCh)
MCh*X
As you can see, this solves the problem (if we ignore the floating point trash that remains.) The vector that results is normalized to have unit norm.
If you want an exact solution, this will do it:
Xsym = null(sym(MCh))
And there we see a nice simple form falls out.
1 个评论
Steven Lord
2022-3-31
You can also get a somewhat nicer basis vector from null by adding the 'r' option.
MCh =[ 1 0 -1 0
5 0 0 -1
0 2 -3 -1
0 1 -4 0];
x = null(MCh, 'r')
While this x looks "nicer" in some sense than the X from your post, if you want to show the rational form of x to make it look even "nicer" you can use the rats function. This agrees with your symbolic solution.
rats(x)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!