solve n unknowns using n+1 equations
7 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (2 件)
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
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
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!