solve n unknowns using n+1 equations

조회 수: 17(최근 30일)
Talaria
Talaria 2012년 4월 24일
how to solve a set of "n+1" equations to find out "n" unknowns.
what i am actually doing is a DC-load flow. any ideas please?

답변(2개)

Walter Roberson
Walter Roberson 2012년 4월 24일
It depends on the form of the equations. If you can express them as linear equations without constraints, then you can use the \ operator, which will do a regression analysis for the best fit (which might leave any particular equation not exact.)
If you are trying to solve analytically using solve() of the symbolic toolbox then solve() will only be able to do it if the rank of the system is n instead of n+1 .
  댓글 수: 2
Friedrich
Friedrich 2012년 4월 25일
You can remove the column with the same index as you specified your x index to be zero,e.g. x(1) = 0 would mean remove first column of A and the first entry of x, x(10) would mean, remove column 10 from A and the entry 10 of x. After that use \ again.
This only works when you set the x entry to zero.

댓글을 달려면 로그인하십시오.


John D'Errico
John D'Errico 2012년 4월 25일
This is easy to do in several ways. I'll start with a rather arbitrary array of data as an example.
A = rand(3,4)
b = rand(3,1)
A =
0.14189 0.79221 0.035712 0.67874
0.42176 0.95949 0.84913 0.75774
0.91574 0.65574 0.93399 0.74313
b =
0.39223
0.65548
0.17119
Now, we can see that backslash solves this linear system, picking one of the unknowns to set to zero.
A\b
ans =
-0.68744
0.59853
0.43708
0
Or, I could use pinv to solve it for a different style of solution, but arguably equally as good.
pinv(A)*b
ans =
-0.69486
0.58673
0.44058
0.015139
A simple way to solve it where any given element will be selected to set at a given value is to use LSE, a code I have placed on the file exchange.
So I'll choose variable 4 to set to zero.
zind = zeros(1,size(A,2));
zind(4) = 1;
lse(A,b,zind,0)
ans =
-0.68744
0.59853
0.43708
0
The nice thing is, I could have picked a different variable, setting it to any given number. So, if I wanted to set the first unknown to pi, that takes nothing more than a simple change:
zind = zeros(1,size(A,2));
zind(1) = 1;
lse(A,b,zind,pi)
ans =
3.1416
6.6954
-1.3746
-7.8213
In fact, this is entirely doable without needing LSE for these simple cases, by dropping out the appropriate column of A and then solving. (I can add that solution if you wish to see it.) Note that in any case, if A is rank deficient (singular) once you remove a column, then there will be a problem.
Finally, you could also have used lsqlin from the optimization toolbox.

Community Treasure Hunt

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

Start Hunting!

Translated by