solve: Cannot find explicit solution but it have solutions, matlab's bug?
1 回表示 (過去 30 日間)
古いコメントを表示
this is my code:
syms x0 x1 x2 x3 x4;
cond1 = (1.00028*x0+1.00045*x1)>=1.00035*(x0+x1);
cond2 = ((1.00028*x0+1.00045*x1) + 1.00063*x2)>=1.00054*(x0+x1+x2);
cond3 = (((1.00028*x0+1.00045*x1) + 1.00063*x2)+1.00082*x3)>=1.00076*(x0+x1+x2+x3);
cond4 = ((((1.00028*x0+1.00045*x1) + 1.00063*x2)+1.00082*x3)+1.00101*x4)>=1.00091*(x0+x1+x2+x3+x4);
cond5 = x0+x1+x2+x3+x4>=0;
condconds = [cond1 cond2 cond3 cond4 cond5];
sol = solve(condconds, [x0 x1 x2 x3 x4])
Does my code have any error or matlab have bugs???
My solution :
x0 1
x1 1
x2 3.44
x3 19.94
x4 38.07
by the way, i just need integer x
6 件のコメント
採用された回答
John D'Errico
2020 年 8 月 14 日
編集済み: John D'Errico
2020 年 8 月 14 日
Look at what you have. A linear system of inequalities. Solve is designed to solve equalities. The solution that you have may be a solution. However, there are infinitely many solutions. One of those solutions must be the zero solution, since your problem is a homogeneous one, with no constant terms.
But, is your "solution truly a solution? I'm afraid not.
vpa(subs(condconds,[x0,x1,x2,x3,x4],[1,1,3.44,19.94,38.07]),10)
ans =
[ 2.0007 <= 2.00073, 5.4429376 <= 5.4428972, 25.3992888 <= 25.399248, 63.5077395 <= 63.5076987, 0.0 <= 63.45]
So the 2nd, 3rd and 4th constraints are all invalidated by your solution, though the errors are small. So I'll ssume you have merely rounded off what may be a valid solution.
Now let me look at the equality form of your constraint system that Stefan found. Is that actually rank deficient?
svd(double(A))
ans =
2.2361
0.00074952
0.00018996
0.00011237
9.3138e-05
NO. Not at all.
Regardless, if we return to the inequality constrained form of your problem, can we find solutions? Probably. A common trick is to use linear programming.
linprog wants <= inequalities, so I'll swap the signs on A.
DA = double(A);
linprog(ones(5,1),-DA,zeros(5,1))
Optimal solution found.
ans =
0
0
0
0
0
linprog(-ones(5,1),-DA,zeros(5,1))
Problem is unbounded.
ans =
[]
So we do find a solution as the zero vector, as we must, since A is actually non-singular. But by looking in another direction, linprog tells us the problem is unbounded. So there are infinitely many solutions in some direction.
Is there a solution where all of the knowns are no smaller than 1?
format long g
>> X = linprog(rand(5,1),-DA,zeros(5,1),[],[],ones(5,1))
Optimal solution found.
X =
1
1
3.88888888889285
21.5925925926071
41.2222222222452
Interesting, in that linprog finds one near what you called the solution. As I said though, there will be infinitely many solutions, but perhaps this will be good enough for you.
その他の回答 (1 件)
Stephan
2020 年 8 月 14 日
Congratulations, you have 1 solution of an infinite number of possible solutions - look to the borderline case of equal to:
syms x0 x1 x2 x3 x4;
assume([x0 x1 x2 x3 x4], {'real', 'positive'})
cond1 = (1.00028*x0+1.00045*x1)==1.00035*(x0+x1);
cond2 = ((1.00028*x0+1.00045*x1) + 1.00063*x2)==1.00054*(x0+x1+x2);
cond3 = (((1.00028*x0+1.00045*x1) + 1.00063*x2)+1.00082*x3)==1.00076*(x0+x1+x2+x3);
cond4 = ((((1.00028*x0+1.00045*x1) + 1.00063*x2)+1.00082*x3)+1.00101*x4)==1.00091*(x0+x1+x2+x3+x4);
cond5 = x0+x1+x2+x3+x4==0;
condconds = [cond1 cond2 cond3 cond4 cond5];
[A,~] = equationsToMatrix(condconds);
det_A = vpa(det(A))
leads to
det_A =
A =
[ -7/100000, 1/10000, 0, 0, 0]
[ -13/50000, -9/100000, 1266637395196663/14073748835532800000, 0, 0]
[ -3/6250, -31/100000, -1829587348620553/14073748835532800000, 3/50000, 0]
[ -8866461766385191/14073748835532800000, -1294784892868923/2814749767106560000, -78812993479/281474976710656, -1266637395197479/14073748835532800000, 450359962737/4503599627370496]
[ 1, 1, 1, 1, 1]
b =
0
0
0
0
0
det_A =
0.0000000000000033319999999983153682592275926204
which means, that the determinant of your system is zero in fact. Since solve is looking for a explicit solution it will not find any i guess.
3 件のコメント
参考
カテゴリ
Help Center および File Exchange で Linear Algebra についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!