numVars = ( n + 1 ) * 3 

> for i in range ( numVars ) : 
>                 eqnList [ i ] = eqnList [ i ] . expand () 
>                 print ( eqnList [ i ] ) 
>
> # the linear equation system is expressed in matrix form as: eqnCoeffs 
> * eqnVars = eqnConstants 
>
> eqnCoeffs = zeros ( numVars, numVars ) 
> eqnVars = Matrix ( numVars, 1, [ Ep ( i ) for i in fromto ( 0, n ) ] + 
> [ De ( i ) for i in fromto ( 0, n ) ] + [ La ( i ) for i in fromto ( 
> 0, n ) ] )


ok, that's being explicit
 

>
> eqnConstants = zeros ( numVars, 1 ) 
>
> for myrow in range ( numVars ) : 
>         eqn = eqnList [ myrow ] 
>         for mycol in range ( numVars ) : 
>                 found = eqn . coeff ( eqnVars [ mycol ] ) 
>                 eqnCoeffs [ myrow, mycol ] = found 
>                 eqn -= found * eqnVars [ mycol ] 
>         eqnConstants [ myrow ] = - eqn 
>
>
That's the verbose way to say eqnCoeffs = 
Matrix(eqn).jacobian(Matrix(eqnVars)) and eqnConstants = eqnCoeffs - 
Matrix(eqn). Here's a toy system:

>>> eqns = (2*x+y+3,x-y-2)
>>> E = Matrix(eqns)
>>> X = Matrix([x, y])
>>> A = E.jacobian(X)
>>> B = A*X-E
>>> A
[2,  1]
[1, -1]
>>> X
[x]
[y]
>>> B
[-3]
[ 2]


 

> print ( eqnCoeffs ) 
> print ( eqnVars . T ) 
> print ( eqnConstants . T ) 
>
> I hope this approach is more straightforward even though it is not as 
> power-user as yours i.e. using as_independent(*X) etc :-) 
>
>  
It's fine...hopefully the above, however, looks a little more text-bookish 
and easier on the fingers.

>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sympy/-/dgB0cj253QUJ.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to