Bug in system solver? why it give wrong answer? here's proof
Show older comments
So i have an equation that i need to solve for Xtest, the rest are constants that have been defined,(T11,T12,R11,L11,L12)
>> T11(counter1,1)
ans =
4.1346 + 3.7345i
>> T12(counter1,1)
ans =
-4.8766 - 1.6522i
>> R11(counter1,1)
ans =
-1.2971 + 3.0915i
>> L11(counter1,1)
ans =
4.8939 + 0.8988i
>> L12(counter1,1)
ans =
-1.7834 + 9.5488i
>> S11e(counter1,1)
ans =
4.7170 + 2.3709i
>> S22e(counter1,1)
ans =
0.0222 - 0.2871i
>> S12e(counter1,1)
ans =
0.3975 - 2.3266i
>> syms Xtest
>> P = ((T11(counter1,1)-L11(counter1,1))/(T12(counter1,1)-(L12(counter1,1)*Xtest)))^2 - ((T12(counter1,1)*Xtest - L12(counter1,1))/(T12(counter1,1)*Xtest - L12(counter1,1)*(Xtest^2)))
P =
- (Xtest*(2745295363781011/562949953421312 + 7440648460943983/4503599627370496*I) - 8031595954485133/4503599627370496 + 335968815892787/35184372088832*I)/(Xtest*(2745295363781011/562949953421312 + 7440648460943983/4503599627370496*I) - Xtest^2*(8031595954485133/4503599627370496 - 335968815892787/35184372088832*I)) - 1/(Xtest*(8031595954485133/4503599627370496 - 335968815892787/35184372088832*I) - 2745295363781011/562949953421312 - 7440648460943983/4503599627370496*I)^2*(591387244714502586985380151581/79228162514264337593543950336 + 2729658162811733403516616363985/633825300114114700748351602688*I)
>> [Xtest] = double(solve (P))
Xtest =
-0.0750 - 0.5247i
-0.0844 + 0.5639i
-0.2597 - 1.7345i
>>
Matlab solve the equation and states that Xtest has 3 values
-0.0750 - 0.5247i
-0.0844 + 0.5639i
-0.2597 - 1.7345i
Xtest(1) is the first value, Xtest(2) is 2nd and Xtest(3)is third. now lets substitude Xtest(1,2&3) into the original equation, it should = to 0, or at least very cose to 0.
but see, only the 2nd and 3rd is =0 the 1st answer is clearly not 0, what went wrong here? is this a bug in matlab?
>> ((T11(counter1,1)-L11(counter1,1))/(T12(counter1,1)-(L12(counter1,1)*Xtest(1))))^2 - ((T12(counter1,1)*Xtest(1) - L12(counter1,1))/(T12(counter1,1)*Xtest(1) - L12(counter1,1)*(Xtest(1)^2)))
ans =
1.1977 + 0.1702i
>> ((T11(counter1,1)-L11(counter1,1))/(T12(counter1,1)-(L12(counter1,1)*Xtest(2))))^2 - ((T12(counter1,1)*Xtest(2) - L12(counter1,1))/(T12(counter1,1)*Xtest(2) - L12(counter1,1)*(Xtest(2)^2)))
ans =
-3.5527e-014 -4.9738e-014i
>> ((T11(counter1,1)-L11(counter1,1))/(T12(counter1,1)-(L12(counter1,1)*Xtest(3))))^2 - ((T12(counter1,1)*Xtest(3) - L12(counter1,1))/(T12(counter1,1)*Xtest(3) - L12(counter1,1)*(Xtest(3)^2)))
ans =
1.7347e-017 -8.6736e-019i
>>
Answers (2)
Walter Roberson
on 16 May 2012
0 votes
It does appear to be a bug. That extra point is one of two singularities (the other singularity is its complex conjugate)
2 Comments
raymond
on 16 May 2012
Walter Roberson
on 16 May 2012
Yes, the answers *should* be ones that substitute back to yield 0. You have correctly identified a bug that is giving back extra answers. The extra answer is at a location where (if you had enough decimal places) the expression would divide by 0. There is no way to make it ignore the wrong answers because it has a bug and does not know they are wrong answers.
raymond
on 16 May 2012
0 votes
Categories
Find more on Mathematics 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!