Post Reply 
linsolve sometimes returns incorrect answer
10-27-2022, 06:02 PM
Post: #1
linsolve sometimes returns incorrect answer
I was solving a system of equations for physics and I came across what appears to be bug in the linsolve (and solve) function.

Code:
linsolve([t1-m3*g=m3*a3, t2-m1*g=m1*a1, t2-m2*g=m2*a2, t1-2*t2=0, a1=-(a2+a3)/2], [t1,t2,a1,a2,a3]);

xcas (and maxima) both give the results to be

Code:
[8*g*m1*m2*m3/(2*m1*m2+m1*m3+2*m2*m3),4*g*m1*m2*m3/(2*m1*m2+m1*m3+2*m2*m3),(-2*g*m1*m2-g*m1*m3+2*g*m2*m3)/(2*m1*m2+m1*m3+2*m2*m3),(-2*g*m1*m2+3*g*m1*m3-2*g*m2*m3)/(2*m1*m2+m1*m3+2*m2*m3),(6*g*m1*m2-g*m1*m3-2*g*m2*m3)/(2*m1*m2+m1*m3+2*m2*m3)]

but the Prime CAS, HW 2.1.14603 (2021-12-02) and VC 2.1.14596 (2021-10-01), returns exactly twice the correct answers
Code:
[16*g*m1*m2*m3/(2*m1*m2+m1*m3+2*m2*m3),8*g*m1*m2*m3/(2*m1*m2+m1*m3+2*m2*m3),(-4*g*m1*m2-2*g*m1*m3+4*g*m2*m3)/(2*m1*m2+m1*m3+2*m2*m3),(-4*g*m1*m2+6*g*m1*m3-4*g*m2*m3)/(2*m1*m2+m1*m3+2*m2*m3),(12*g*m1*m2-2*g*m1*m3-4*g*m2*m3)/(2*m1*m2+m1*m3+2*m2*m3)]

However, if I change the last equation from a1=-(a2+a3)/2 to the equivalent 2*a1=-(a2+a3), then the answers are correct.

Also, if I plug in numeric values into the original equations, such as
Code:
linsolve([t1-30*10=30*a3, t2-10*10=10*a1, t2-20*10=20*a2, t1-2*t2=0, a1=-(a2+a3)/2], [t1,t2,a1,a2,a3]);
it produces the correct results.
Code:
[4800/19,2400/19,50/19,-70/19,-30/19]
Find all posts by this user
Quote this message in a reply
10-30-2022, 02:43 PM (This post was last modified: 10-30-2022 02:44 PM by Wes Loewer.)
Post: #2
RE: linsolve sometimes returns incorrect answer
Seems that this bug was introduced back in 2017.

I can confirm the following:
firmware 11226 (2016-12-08) does not have this bug
firmware 11385 (2017-01-27) has this bug
Find all posts by this user
Quote this message in a reply
10-30-2022, 03:57 PM
Post: #3
RE: linsolve sometimes returns incorrect answer
We have the same bug for XCas 1.5.0-63 (win32), returning twice the correct answer.
Find all posts by this user
Quote this message in a reply
10-30-2022, 05:34 PM
Post: #4
RE: linsolve sometimes returns incorrect answer
(10-30-2022 03:57 PM)Albert Chan Wrote:  We have the same bug for XCas 1.5.0-63 (win32), returning twice the correct answer.

Since xcas 1.9.0-7 does not have the bug anymore, perhaps it's already been fixed in the Prime CAS which we'll hopefully see it in the next firmware.
Find all posts by this user
Quote this message in a reply
05-21-2023, 11:22 AM
Post: #5
RE: linsolve sometimes returns incorrect answer
(10-30-2022 05:34 PM)Wes Loewer Wrote:  
(10-30-2022 03:57 PM)Albert Chan Wrote:  We have the same bug for XCas 1.5.0-63 (win32), returning twice the correct answer.

Since xcas 1.9.0-7 does not have the bug anymore, perhaps it's already been fixed in the Prime CAS which we'll hopefully see it in the next firmware.

I'm surprised that this bug which was fixed in xcas quite some time back is still present in the recently released Prime firmware.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)