Python Forum

Full Version: SOlving LInear Equations in Python(Symoy, NUmpy) - Coefficient Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello I am trying to solve set of equations and I actually know the how to solve them but I am having some problems and for some reason I cannot give the coefficients correctly I guess

So, Here is my equations:

(a + d)*(rho00*(a + d) + rho10*(b - 1.0*I*c)) + (b + 1.0*I*c)*(rho01*(a + d) + rho11*(b - 1.0*I*c)) = rho00
(a - d)*(rho01*(a + d) + rho11*(b - 1.0*I*c)) + (b - 1.0*I*c)*(rho00*(a + d) + rho10*(b - 1.0*I*c)) = 0.937*rho01
(a + d)*(rho00*(b + 1.0*I*c) + rho10*(a - d)) + (b + 1.0*I*c)*(rho01*(b + 1.0*I*c) + rho11*(a - d))=0.9358*rho10
(a - d)*(rho01*(b + 1.0*I*c) + rho11*(a - d)) + (b - 1.0*I*c)*(rho00*(b + 1.0*I*c) + rho10*(a - d))=0.98*rho11
And I wrote this code line after all
#sympy.linsolve([dwe[0][0]-exp_idt[0][0], dwe[0][1]-exp_idt[1][1],dwe[1][0]-exp_idt[2][2],dwe[1][1]-exp_idt[3][3] ], (a, b, c,d))
But I got a never endless error :////
How to solve this set of equations?
Fyi, here is my arrays:
exp_idt=[ 1.   ,  0.   ,  0.   ,  0.   ],
              [-0.   ,  0.937, -0.004, -0.005],
              [ 0.023,  0.014,  0.935, -0.03 ],
              [ 0.011, -0.009,  0.017,  0.983]]
dwe=[[(a + d)*(rho00*(a + d) + rho10*(b - 1.0*I*c)) + (b + 1.0*I*c)*(rho01*(a + d) + rho11*(b - 1.0*I*c))
  (a - d)*(rho01*(a + d) + rho11*(b - 1.0*I*c)) + (b - 1.0*I*c)*(rho00*(a + d) + rho10*(b - 1.0*I*c))]
 [(a + d)*(rho00*(b + 1.0*I*c) + rho10*(a - d)) + (b + 1.0*I*c)*(rho01*(b + 1.0*I*c) + rho11*(a - d))



  (a - d)*(rho01*(b + 1.0*I*c) + rho11*(a - d)) + (b - 1.0*I*c)*(rho00*(b + 1.0*I*c) + rho10*(a - d))]]
The equations are not linear. Linsolve can solve only systems of linear equations.
well, the problem is here a,b,c,d are variables which I want to find them but rho00, rho01 rho10, rho11 are the free varibles which will not take a value and I do not know how to give these equations to python. Otherwise I can use
fsolve
for non linear equations or
nonlinear solver
is one of the tool too. But I do not know how to give these equations to python to solve them with free variables