solve n unknowns using n+1 equations

10 views (last 30 days)
Talaria
Talaria on 24 Apr 2012
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?

Answers (2)

Walter Roberson
Walter Roberson on 24 Apr 2012
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 Comments
Talaria
Talaria on 25 Apr 2012
thank you Walter, but my problem is different, as follows:
i understand if i have b=Ax
where A is the matrix of coefficients for the equations and x is the set of unknowns, i could find the unknowns by: x=A\b
but what i want to do is set any of the unknowns to "0", say for example: x(1)=0, now i want the code to find the rest of "x"; x(2), x(3), etc.. given the same set of equations and the first x(1) to be zero. is there any way to do so??
Friedrich
Friedrich on 25 Apr 2012
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.

Sign in to comment.


John D'Errico
John D'Errico on 25 Apr 2012
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!