The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





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
Post Reply 


Messages In This Thread
linsolve sometimes returns incorrect answer - Wes Loewer - 10-27-2022 06:02 PM



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