MATLAB Answers

solve n unknowns using n+1 equations

8 views (last 30 days)
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 .
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 =
Now, we can see that backslash solves this linear system, picking one of the unknowns to set to zero.
ans =
Or, I could use pinv to solve it for a different style of solution, but arguably equally as good.
ans =
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;
ans =
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;
ans =
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!