# How to solve a simple Matrix equation?

5 ビュー (過去 30 日間)
Phillipp 2020 年 2 月 19 日

Hello,
I have a small problem. I want to solve the multiplication of a given matrix.
For Example:
A = [-1,0,0,1;1,-1,0,0;0,1,-1,0;0,0,1,-1];
x = sym('x', [4,1]);
x(1,1)=1;
solve(A*x==[0;0;0;0])
Because I am a beginner at Matlab, I really don't know what im doing wrong. In this Example x should be equal to ones.
The goal is, to use it for a big matrix and calculate all unknown 'x'. If it is not possible to calculate them, I have to estimate the missing x, and solve it with something like a Netwon-Raphson method. But that will propably be in a later question.

#### 0 件のコメント

サインイン to comment.

### 採用された回答

Jon 2020 年 2 月 19 日

It looks like you want to find all of the vectors satisfying Ax = 0 for some singular matrix , A. If so, you can do this using
X = null(A)
This returns a basis for the null space of a matrix A.
In your case MATLAB returns X = [0.5;0.5;0.5;0.5], any multiple of this will satisfy your equation,
so for example 2*[0.5;0.5;0.5,0.5] = [1;1;1;1] is a solution and you can verify that A*[1;1;1;1]=0
To find out more about the null function type doc null on the command line in MATLAB

#### 7 件のコメント

Jon 2020 年 2 月 20 日
Here are a couple of other approaches.
You could modify the above to use a linear objective function instead of a quadratic one and instead use linprog which I think is available without any special toolboxes.
Another partial idea is that you could move the columns in A (the incidence matrix) that correspond to the known flows over to the right hand side of the equation. So if the original system were Ax = 0, you would instead have Au*xu = -An*xn where Au,xu are the columns corresponding to the unknown flows, and the unknown flows An,xn are the columns corresponding to the known flows and xn are the known flows. Note that -An*xn is just a vector, call, it b. Then this puts equations in for Au*xu = b. Which can be solved using pinv, or Matlab \ . This at least enforces the known flow constraints, but I'm not sure how you would enforce the positivity conststraint (flows must be greater than zero)
If you have lsqlin then maybe just stick with that.
Phillipp 2020 年 2 月 20 日
I have the optimization toolbox installed.Thank you! That really helped me.
You made a tiny mistake you have to change this:
lb = zeros(numNodes,1); % lower bound, flows must be greater than zero
to this.
lb = zeros(numPipes,1); % lower bound, flows must be greater than zero
But man, you really helped me out. Thanks a lot.
Jon 2020 年 2 月 20 日
Good catch!
Glad it seem like this approach will help you. One benefit of the least squares minimization, is that it very naturally handles the situation where you have sensor measurements of the flows but they may be noisy/slightly in error. Imagine that you in fact have all of the flows measured with noisy measurements. The measured flows will not satisfy Ax = 0 but you can find a set of flows which are as close as possible to the measured values (in the least square sense) but that satisfy Ax = 0. This is in some sense best physically consistent estimate of the overall network flows.

サインイン to comment.

### その他の回答 (0 件)

サインイン してこの質問に回答します。

Translated by