The system of equations (64 equations -12 unknown) solution help
Show older comments
Regards, when programming an application I faced with the following system of equations
n1=i1*i5*i9
n2=i1*i5*i10
n3=i1*i5*i11
n4=i1*i5*i12
n5=i1*i6*i9
n6=i1*i6*i10
n7=i1*i6*i11
n8=i1*i6*i12
n9=i1*i7*i9
n10=i1*i7*i10
n11=i1*i7*i11
n12=i1*i7*i12
n13=i1*i8*i9
n14=i1*i8*i10
n15=i1*i8*i11
n16=i1*i8*i12
n17=i2*i5*i9
n18=i2*i5*i10
n19=i2*i5*i11
n20=i2*i5*i12
n21=i2*i6*i9
n22=i2*i6*i10
n23=i2*i6*i11
n24=i2*i6*i12
n25=i2*i7*i9
n26=i2*i7*i10
n27=i2*i7*i11
n28=i2*i7*i12
n29=i2*i8*i9
n30=i2*i8*i10
n31=i2*i8*i11
n32=i2*i8*i12
n33=i3*i5*i9
n34=i3*i5*i10
n35=i3*i5*i11
n36=i3*i5*i12
n37=i3*i6*i9
n38=i3*i6*i10
n39=i3*i6*i11
n40=i3*i6*i12
n41=i3*i7*i9
n42=i3*i7*i10
n43=i3*i7*i11
n44=i3*i7*i12
n45=i3*i8*i9
n46=i3*i8*i10
n47=i3*i8*i11
n48=i3*i8*i12
n49=i4*i5*i9
n50=i4*i5*i10
n51=i4*i5*i11
n52=i4*i5*i12
n53=i4*i6*i9
n54=i4*i6*i10
n55=i4*i6*i11
n56=i4*i6*i12
n57=i4*i7*i9
n58=i4*i7*i10
n59=i4*i7*i11
n60=i4*i7*i12
n61=i4*i8*i9
n62=i4*i8*i10
n63=i4*i8*i11
n64=i4*i8*i12
The system of equations resulting from these matrix, with permutation of all elements
i1 i5 i9
i2 i6 i10
i3 i7 i11
i4 i8 i12
In the above equations, n (n1, n2 ..., n64) are familiar values, while the i (i1, i2, ..., i12) are unknown values
After replace the unknowns by their logarithms i have next system
t1=log(i1)+log(i5)+log(i9)
t2=log(i1)+log(i5)+log(i10)
t3=log(i1)+log(i5)+log(i11)
t4=log(i1)+log(i5)+log(i12)
t5=log(i1)+log(i6)+log(i9)
t6=log(i1)+log(i6)+log(i10)
t7=log(i1)+log(i6)+log(i11)
t8=log(i1)+log(i6)+log(i12)
t9=log(i1)+log(i7)+log(i9)
t10=log(i1)+log(i7)+log(i10)
t11=log(i1)+log(i7)+log(i11)
t12=log(i1)+log(i7)+log(i12)
t13=log(i1)+log(i8)+log(i9)
t14=log(i1)+log(i8)+log(i10)
t15=log(i1)+log(i8)+log(i11)
t16=log(i1)+log(i8)+log(i12)
t17=log(i2)+log(i5)+log(i9)
t18=log(i2)+log(i5)+log(i10)
t19=log(i2)+log(i5)+log(i11)
t20=log(i2)+log(i5)+log(i12)
t21=log(i2)+log(i6)+log(i9)
t22=log(i2)+log(i6)+log(i10)
t23=log(i2)+log(i6)+log(i11)
t24=log(i2)+log(i6)+log(i12)
t25=log(i2)+log(i7)+log(i9)
t26=log(i2)+log(i7)+log(i10)
t27=log(i2)+log(i7)+log(i11)
t28=log(i2)+log(i7)+log(i12)
t29=log(i2)+log(i8)+log(i9)
t30=log(i2)+log(i8)+log(i10)
t31=log(i2)+log(i8)+log(i11)
t32=log(i2)+log(i8)+log(i12)
t33=log(i3)+log(i5)+log(i9)
t34=log(i3)+log(i5)+log(i10)
t35=log(i3)+log(i5)+log(i11)
t36=log(i3)+log(i5)+log(i12)
t37=log(i3)+log(i6)+log(i9)
t38=log(i3)+log(i6)+log(i10)
t39=log(i3)+log(i6)+log(i11)
t40=log(i3)+log(i6)+log(i12)
t41=log(i3)+log(i7)+log(i9)
t42=log(i3)+log(i7)+log(i10)
t43=log(i3)+log(i7)+log(i11)
t44=log(i3)+log(i7)+log(i12)
t45=log(i3)+log(i8)+log(i9)
t46=log(i3)+log(i8)+log(i10)
t47=log(i3)+log(i8)+log(i11)
t48=log(i3)+log(i8)+log(i12)
t49=log(i4)+log(i5)+log(i9)
t50=log(i4)+log(i5)+log(i10)
t51=log(i4)+log(i5)+log(i11)
t52=log(i4)+log(i5)+log(i12)
t53=log(i4)+log(i6)+log(i9)
t54=log(i4)+log(i6)+log(i10)
t55=log(i4)+log(i6)+log(i11)
t56=log(i4)+log(i6)+log(i12)
t57=log(i4)+log(i7)+log(i9)
t58=log(i4)+log(i7)+log(i10)
t59=log(i4)+log(i7)+log(i11)
t60=log(i4)+log(i7)+log(i12)
t61=log(i4)+log(i8)+log(i9)
t62=log(i4)+log(i8)+log(i10)
t63=log(i4)+log(i8)+log(i11)
t64=log(i4)+log(i8)+log(i12)
All variables are > 0
How to solve this system for (i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12)
Thanks in advance
9 Comments
Azzi Abdelmalek
on 20 Jan 2013
Why are you replacing with logarithm?
Image Analyst
on 20 Jan 2013
You aren't really using 64 and 12 separately named variables rather than an array are you? If you are, make life easier on yourself and use arrays.
aa aa
on 20 Jan 2013
Roger Stafford
on 20 Jan 2013
It is important to realize that in general if you have more equations than unknowns, it is likely there will exist no solutions to all of them. In your particular case with 64 equations and only 12 unknowns to adjust you should be very suspicious about ever finding a simultaneous solution to all of them. In fact it is very easy to show that there will have to be heavy restrictions on the n-values to allow a solution to exist. For example you must have n1/n2 = n5/n6. If that isn't true there will be no general solution.
aa aa
on 20 Jan 2013
Roger Stafford
on 20 Jan 2013
What do you mean by "standardized numbers"?
aa aa
on 20 Jan 2013
Roger Stafford
on 21 Jan 2013
The n's are a geometric progression? The ratio of successive elements of n are always the same? That is information that should have been given to us long ago! I have placed an answer below based on this assumption.
Answers (5)
A matrix-vector equation of the form A*x=b (which you have) can be solved by
x=A\b
Azzi Abdelmalek
on 20 Jan 2013
% Look at this example
n1=i1*i5*i4
n2=i2*i5*i3
n3=i1*i5*i2
n4=i1*i4*i3
----------------------
Fi=[1 0 0 1 1;0 1 1 0 1;1 1 0 0 1;1 0 1 1 0]
y=[n1;n2;n3;n4]
out=Fi\y
16 Comments
aa aa
on 20 Jan 2013
Azzi Abdelmalek
on 20 Jan 2013
no,
n1=4;
n2=3;
n3=10;
n4=5;
y=[n1;n2;n3;n4]
% n1,n2,n3, and n4 are constants
Azzi Abdelmalek
on 20 Jan 2013
Edited: Azzi Abdelmalek
on 20 Jan 2013
If you have a system
a1*x+b1*y=c1
a2*x+b2*y=c2
Fi=[a1 b1;a2 b2]
y=[c1;c2]
you can write your system as
Fi*v=y ; with unknown variable v=[x;y]
The solution is given by least square method
v=Fi\y
Azzi Abdelmalek
on 20 Jan 2013
Edited: Azzi Abdelmalek
on 20 Jan 2013
for the first line you have n1=i1+i5+i9 which means the first line of Fi will be
[ 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 ...
this line contains 64 elements
aa aa
on 20 Jan 2013
Azzi Abdelmalek
on 20 Jan 2013
Edited: Azzi Abdelmalek
on 20 Jan 2013
Fi is a matrix 64x12, to make it easy to find, using regexp and regexprep I've found idx from your post.
idx=[ 1 5 9
1 5 10
1 5 11
1 5 12
1 6 9
1 6 10
1 6 11
1 6 12
1 7 9
1 7 10
1 7 11
1 7 12
1 8 9
1 8 10
1 8 11
1 8 12
2 5 9
2 5 10
2 5 11
2 5 12
2 6 9
2 6 10
2 6 11
2 6 12
2 7 9
2 7 10
2 7 11
2 7 12
2 8 9
2 8 10
2 8 11
2 8 12
3 5 9
3 5 10
3 5 11
3 5 12
3 6 9
3 6 10
3 6 11
3 6 12
3 7 9
3 7 10
3 7 11
3 7 12
3 8 9
3 8 10
3 8 11
3 8 12
4 5 9
4 5 10
4 5 11
4 5 12
4 6 9
4 6 10
4 6 11
4 6 12
4 7 9
4 7 10
4 7 11
4 7 12
4 8 9
4 8 10
4 8 11
4 8 12]
Fi=zeros(64);
for k=1:64
Fi(k,idx(k,:))=1
end
aa aa
on 20 Jan 2013
Azzi Abdelmalek
on 20 Jan 2013
Edited: Azzi Abdelmalek
on 20 Jan 2013
You don't need to use syms, I show you how to find Fi (it's done, look at above comment). you have just to build the vector y=[t1;t2;...;t64]; then
Sol=Fi\y
aa aa
on 20 Jan 2013
Azzi Abdelmalek
on 20 Jan 2013
Edited: Azzi Abdelmalek
on 20 Jan 2013
That means, your solutions can't be determined. With a matrix Fi formed essentially by zeros!
aa aa
on 20 Jan 2013
Azzi Abdelmalek
on 20 Jan 2013
Edited: Azzi Abdelmalek
on 20 Jan 2013
Sorry there is an error in Fi, the initialization is Fi=zeros(64,12)
Azzi Abdelmalek
on 20 Jan 2013
Edited: Azzi Abdelmalek
on 20 Jan 2013
Use instead
Fi=zeros(64,12); % this line that causes a problem
for k=1:64
Fi(k,idx(k,:))=1
end
aa aa
on 20 Jan 2013
Azzi Abdelmalek
on 20 Jan 2013
Edited: Azzi Abdelmalek
on 20 Jan 2013
You have 64 equations for 12 unknowns variables, Least square method minimize the error, but don't make it zero. More you have equations, more there is a chance that the error will be bigger
aa aa
on 20 Jan 2013
aa aa
on 20 Jan 2013
6 Comments
Image Analyst
on 20 Jan 2013
Edited: Image Analyst
on 20 Jan 2013
I don't know what that second set of numbers is. In the first set, you have 8 measurements, and 6 variables. So you have
y = Ax
with
y = [14;11;13;10;13;10;12;9];
and A = the rows with each row being the coefficients for [a,b,c,d,e,f]. If the variable is missing for that measurement, put a zero in for it. So each row should have 6 coefficients. So in that example, A is
A = [1, 0, 1, 0, 1, 0;... % Only a, c, and e present.
1, 0, 1, 0, 0, 1;... % Only a, c, and f present.
1, 0, 0, 0, 1, 1, 0;... % Only a, d, e present.
etc. down to the last row:
0, 1, 0, 1, 0, 1]; % Only b, d, and f present.
To get the coefficients of the fit
yFitted = alpha(1) * a + alpha(2) * b + alpha(3) * c + alpha(4) * d + alpha(5) * e + alpha(6) * f, you use alpha = A\y.
shorter example but similar:
I don't see the similarity, really. You should probably post this as a new question.
has 27 solutions keeping the variables > 0 ; (a,b,c,d,e,f):
That can only be true if you also insist that a...f are positive integers. Otherwise, there would be either only one or infinite least squares solutions. You didn't insist on integer-valued solutions in your first example, which makes it very different from your originally posted question.
If your question is how to find the 27 solutions, you will probably have to enumerate all of the integer solutions and do exhaustive search. A quick analysis of your equations shows that b,d,f can be at most 7, a,c can be at most 8, and e can be at most 10. To get all combinations needed for the search,
P=uint8(1:7);
Q=uint8(1:8);
R=uint8(1:10);
[b,d,f,a,c,e]=ndgrid(P,P,P,Q,Q,R);
When I do the search, I find 28 solutions, by the way. Not 27.
Azzi Abdelmalek
on 20 Jan 2013
%Let us make it shorter
- a+c+e = 14
- a+c+d = 11
- a+d+e = 13
- a+b+e = 10
% This can be written
- 1*a+0*b+1*c+0*d+1*e=14
- 1*a+0*b+1*c+1*d+0*e=11
- 1*a+0*b+0*c+1*d+1*e=13
- 1*a+1*b+0*c+0*d+1*e=10
%or
Fi*u=y
%with
Fi=[1 0 1 0 1
1 0 1 1 0
1 0 0 1 1
1 1 0 0 1]
y=[14;11;13;10]
The solution is
sol=Fi\y
Image Analyst
on 20 Jan 2013
Why do they have to be all positive? Just because he said "All variables are > 0" doesn't mean the coefficients of the regression have to be positive. And I think that if you have more equations (i.e. measurements or observations) than variables, that the "solution" is just a normal run-of-the-mill regression formula, not an exact solution for every single equation, which all of us agree is impossible (unless the numbers just happen to work out that way).
Matt J
on 21 Jan 2013
Why do they have to be all positive? Just because he said "All variables are > 0" doesn't mean the coefficients of the regression have to be positive.
I'm not sure what distinction you're drawing between "variables" and "coefficients of the regression". They seem one and the same to me.
Also, like I said, I ran a search for all integer solutions a,b,c,d,e,f>0 and I got 28 solutions. That's very close to the number of solutions, 27, that the OP said s/he was looking for.
Roger Stafford
on 21 Jan 2013
Are you saying the n's are a geometric progression? Why didn't you tell us that at the beginning? This information is essential to solving your problem! If that is what are now saying, the solutions to your equation can be characterized in the following manner.
Let r be the constant ratio between any two successive n's. Then the solutions are:
i1 = a
i2 = a*r^16
i3 = a*r^32
i4 = a*r^48
i5 = b
i6 = b*r^4
i7 = b*r^8
i8 = b*r^12
i9 = c
i10 = c*r
i11 = c*r^2
i12 = c*r^3
where a, b, and c are any numbers such that a*b*c = n1.
In other words there are just two degrees of freedom in the solutions for any given geometric progression of n's.
aa aa
on 22 Jan 2013
2 Comments
Roger Stafford
on 22 Jan 2013
There can be no solution to that problem! Just take the first four equations:
a1*b1*c1=22,4
a1*b1*c2=28
a1*b2*c1=35,5
a1*b2*c2=45
Divide the second equation by the first and obtain
c2/c1 = 28/22.4 = 1.25
Divide the fourth equation by the third and get
c2/c1 = 45/35.5 =1.2676
Close but no cigar!
aa aa
on 23 Jan 2013
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!