You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Python API of Casadi, is there any equivalent to the A\b command of Matlab? This is what I tried
fromcasadiimport*A=DM([[1.0,3.0,5.0],[2.0,4.0,1.0]]) #A is 2x3b=DM([[1.0],[5.0]]) #b is 2x1solve(A,b) #Fails with Assertion "a.size1() == a.size2()" failed: solve: A not square but 2x3solve(A,b,"lapackqr") #Fails with Segmentation fault (core dumped)solve(A,b,"lapacklu") #Return [-nan, inf]solve(A,b,"lsqr") #Returns [0.636364, 1.07487] Why does it have only 2 elements instead of 3?solve(A,b,"ma27") #Return [-0.338028, 1.69014] Why does it have only 2 elements instead of 3?
In Matlab this works as follows:
A = [135;
241];
b = [1;5];
A\b%It returns [0 1.4118 -0.6471]'
The linear solvers might not handle non-square systems well. For overdetermined systems, you should be able to solve the normal equations. For underdetermined systems, maybe use QR:
importcasadiascaA=ca.DM([[1.0,3.0,5.0],[2.0,4.0,1.0]]) #A is 2x3b=ca.DM([[1.0],[5.0]]) #b is 2x1# Underdetermined system of equation, QR factorization of A transposeQ, R=ca.qr(A.T)
# A*x = b <=> R.T*Q.T*x = bx=ca.mtimes(Q, ca.solve(R.T, b))
x# least-squares solution
Alternatively, consider reformulating your problem so that you don't get an underdetermined system of equations.
In the Python API of Casadi, is there any equivalent to the A\b command of Matlab? This is what I tried
In Matlab this works as follows:
I read the examples at https://github.com/casadi/casadi/blob/main/test/python/linearsolver.py but couldn't find the solution
Thanks!
The text was updated successfully, but these errors were encountered: