Error in solve function - constraining variables
显示 更早的评论
DATA: Available in the attached excel sheet,
T900(1) = cellB3; T900(2) = cellB4; T1000(1) = cellC3
so on and so forth!
A= -1.830; B= 5347
Numerator1=((10^(A+(B/T900(1)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(2)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(3)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(4)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(5)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(6)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(7)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(8)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(9)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(10)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(11)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(12)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(13)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(14)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(15)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(16)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(17)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(18)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(19)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(20)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(21)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(22)))*4.3018*2.59)/1.386294);
Numerator2=((10^(A+(B/T1000(1)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(2)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(3)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(4)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(5)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(6)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(7)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(8)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(9)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(10)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(11)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(12)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(13)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(14)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(15)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(16)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(17)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(18)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(19)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(20)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(21)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(22)))*4.3018*2.59)/1.386294);
Numerator3=((10^(A+(B/T1100(1)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(2)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(3)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(4)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(5)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(6)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(7)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(8)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(9)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(10)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(11)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(12)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(13)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(14)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(15)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(16)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(17)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(18)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(19)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(20)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(21)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(22)))*4.3018*2.59)/1.386294);
Ratio1 = ((Numerator1)/3.63E-06);
Ratio2 = ((Numerator2)/5.72E-06);
Ratio3 = ((Numerator3)/8.87E-06);
Solx = solve([(Ratio1)+(Ratio2)+(Ratio3) ==3,-6.36812==A+(B*8.52E-04),-6.09207==A+(B*7.85E-04),-5.70056==A+(B*7.28E-04)], [A,B])
Invalid MEX-file 'C:\Program Files\MATLAB\R2015b\toolbox\symbolic\symbolic\mupadmex.mexw64': The specified
module could not be found.
Error in mupadengine/evalin (line 111)
res = mupadmex(statement,output_type{:});
Error in solve>getEqns (line 399)
argv{k} = evalin(symengine, 'FALSE');
Error in solve (line 225)
[eqns,vars,options] = getEqns(varargin{:});
Could some one please explain the error message for me? I am trying to perfect the values of A and B so that it fits all 4 equations! If you can think of any other method to do it please do suggest some. Thank you!
回答(1 个)
Walter Roberson
2016-5-15
Your Symbolic Toolbox is not correctly installed.
On the other hand, you are asking to solve 4 equations for two variables that have already been assigned numeric values. Even if we guess that maybe A and B should be
syms A B
without numeric values, since you look like you are solving for A and B, you still end up with 4 equations in two unknowns.
You are also asking to solve(), which is asking for algebraic solutions, exact solutions, but you are using lots and lots of floating point data, which suggests that you should be looking for numeric solutions instead of algebraic solutions.
If you take the second of your equations as being correct but assuming that A and B should be symbolic, and you solve for either of the variables and do a substitution into the left side of your first equation (sum of ratios), then with a small bit of graphing you can show that the left side of the first equation is no less than 32.42088640, and so the sum of the ratios cannot possibly be 3 if A and B are symbolic and the second equation is true.
All in all it appears that your equations are incorrect.
13 个评论
AluAl
2016-5-16
Walter Roberson
2016-5-16
That would give you one equation in two unknowns which would have infinite solutions
AluAl
2016-5-16
Walter Roberson
2016-5-16
No, not with one equation with two unknowns. You could give it one or the other value and have it calculate the second, but that would not be optimization. It would, though, involve finding a numeric root of a sum of exponentials.
AluAl
2016-5-17
Walter Roberson
2016-5-18
... No?
The sum of the three ratios can be any positive value, and for any given real A there is a B that gives that sum, and for any given real B there is an A that gives that sum.
The sum is much more sensitive to changes in A than to changes in B
You could make it more interesting by putting constraints on A or B, like one of them must be non-negative. Be careful, though: if you require that both are non-negative then the smallest sum you can get is about 9800.
Walter Roberson
2016-5-20
num = xlsread('Matlabdata.xlsx');
T900 = sym(num(:,1));
T1000 = sym(num(:,2));
T1100 = sym(num(:,3));
syms A B
Numerator1=((10^(A+(B/T900(1)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(2)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(3)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(4)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(5)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(6)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(7)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(8)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(9)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(10)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(11)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(12)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(13)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(14)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(15)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(16)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(17)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(18)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(19)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(20)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(21)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T900(22)))*sym(4.3018)*sym(2.59))/sym(1.386294));
Numerator2=((10^(A+(B/T1000(1)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(2)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(3)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(4)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(5)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(6)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(7)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(8)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(9)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(10)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(11)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(12)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(13)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(14)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(15)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(16)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(17)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(18)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(19)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(20)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(21)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1000(22)))*sym(4.3018)*sym(2.59))/sym(1.386294));
Numerator3=((10^(A+(B/T1100(1)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(2)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(3)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(4)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(5)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(6)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(7)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(8)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(9)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(10)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(11)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(12)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(13)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(14)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(15)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(16)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(17)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(18)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(19)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(20)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(21)))*sym(4.3018)*sym(2.59))/sym(1.386294))+((10^(A+(B/T1100(22)))*sym(4.3018)*sym(2.59))/sym(1.386294));
Ratio1 = ((Numerator1)/sym(3.63E-06));
Ratio2 = ((Numerator2)/sym(5.72E-06));
Ratio3 = ((Numerator3)/sym(8.87E-06));
solA = solve(Ratio1+Ratio2+Ratio3==3,A);
bestB = 0; %constrain to non-negative
bestA = double(subs(solA,B,bestB));
If you increase B then bestA will decrease, so this is the least-negative A with non-negative B such that the ratio is 3.
AluAl
2016-6-2
编辑:Walter Roberson
2016-6-2
Walter Roberson
2016-6-2
编辑:Walter Roberson
2016-6-2
endNumerator1 = @(A,B) ((10^(A+(B/T900(1)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(2)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(3)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(4)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(5)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(6)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(7)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(8)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(9)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(10)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(11)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(12)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(13)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(14)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(15)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(16)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(17)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(18)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(19)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(20)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(21)))*4.3018*2.59)/1.386294)+((10^(A+(B/T900(22)))*4.3018*2.59)/1.386294);
Numerator2 = @(A,B) ((10^(A+(B/T1000(1)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(2)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(3)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(4)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(5)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(6)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(7)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(8)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(9)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(10)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(11)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(12)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(13)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(14)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(15)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(16)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(17)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(18)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(19)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(20)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(21)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1000(22)))*4.3018*2.59)/1.386294);
Numerator3 = @(A,B) ((10^(A+(B/T1100(1)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(2)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(3)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(4)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(5)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(6)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(7)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(8)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(9)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(10)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(11)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(12)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(13)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(14)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(15)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(16)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(17)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(18)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(19)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(20)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(21)))*4.3018*2.59)/1.386294)+((10^(A+(B/T1100(22)))*4.3018*2.59)/1.386294);
Diff1 = @(A,B) abs(Numerator1(A,B)-3.63E-06);
Diff2 = @(A,B) abs(Numerator2(A,B)-5.72E-06);
Diff3 = @(A,B) abs(Numerator3(A,B)-8.87E-06);
Optimin = @(A,B)Diff1(A,B)+Diff2(A,B)+Diff3(A,B);
[y,fval] = fminsearch( @(AB) Optimin(AB(1),AB(2)), [-1.8380,-5347])
AluAl
2016-6-2
Walter Roberson
2016-6-2
I have corrected a typing mistake on my last line.
AluAl
2016-6-7
类别
在 帮助中心 和 File Exchange 中查找有关 Numeric Solvers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!