I have a system of linear equations in variables $A_n$ of form: $$ \sum _{k=-K}^K h_k A_{n-k} J_{n-k}\left(\frac{(1-i) \text{$\eta $Sqrt}(n-k)}{\sqrt{2}}\right)+A_n\left(\frac{(1-i) \eta \sqrt{n-k} J_{n-1}\left(\frac{(1-i) \sqrt{n-k} \eta }{\sqrt{2}}\right)}{\sqrt{2}}-(n-k) J_n\left(\frac{(1-i) \sqrt{n-k} \eta }{\sqrt{2}}\right)\right)=t_n $$
How can I transform it into a matrix form in Mathematica?
I need it to put this matrix into a Gaussian elimination procedure (https://mathematica.stackexchange.com/q/84324/29728) and get these $A_n$.
If that's important, $t_n$ is a coefficient from Fourier series $t_n=\frac{\int_0^{2 \pi } e^{-\text{in$\phi $}} t(\phi ) \, d\phi }{2 \pi }$, also $h_k=\frac{\int_0^{2 \pi } e^{-\text{ik$\phi $}} h(\phi ) \, d\phi }{2 \pi }$, and variables $A_n$ are coefficients of the Fourier series $F(r,\phi )=\sum _{n=-N}^N e^{\text{in$\phi $}} A_n J_n\left(\frac{(1-i) r \eta }{\sqrt{2}}\right)$

  • $\begingroup$ What are the boundary conditions? $\endgroup$
    – dantopa
    Commented May 27, 2015 at 1:09
  • $\begingroup$ the first equation is a transformed Robin BC for PDE. $\endgroup$
    – Hedin
    Commented May 27, 2015 at 9:19
  • $\begingroup$ your definition of h_k is independent of k. I assume you meant to replace the variable n there. $\endgroup$ Commented May 27, 2015 at 10:34
  • $\begingroup$ @SjoerdC.deVries you're right, my negligence. Done. $\endgroup$
    – Hedin
    Commented May 27, 2015 at 12:52

1 Answer 1


I think the function you are looking for is CoefficientArrays; here is its documentation.

Your system is quite complex so I will let you deal with its intricacies, but here is a demonstration on a toy example.

Let's define a set of linear equations in $x$, $y$, and $z$:

eqns = {2 x - y + 4 z == 12, 3 x + 2 y + z == 10, -y + z == 1};

The solutions of this system are of course $x=1, y=2, z=3$.

Once you have your system represented as a list of equations, use CoefficientArrays to transform them into matrix form:

linsystem = CoefficientArrays[eqns, {x, y, z}];

{ {-12, -10, -1}, { {2, -1, 4}, {3, 2, 1}, {0, -1, 1} } }

CoefficientArrays returns the coefficients as SparseArray objects, which is why I used Normal to visualize them as regular arrays, but you should be able to use the SparseArrays directly in further computation.

You can then feed those matrices to your Gaussian elimination routines, or alternatively use Mathematica's built-in linear system solver, LinearSolve:

LinearSolve[#2, -#1] & @@ linsystem

{1, 2, 3}

The $(-1)$ coefficient I used in the second argument to LinearSolve is a product of how CoefficientArrays interprets equations in its input, rather than plain polynomials, as mentioned in the "Details" section of the documentation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.