Search code examples
matrixwolfram-mathematicadifferential-equations

Convert table to matrix equation


my table looks like this:

 {975/2048 - 512 y[1] + 256 y[2]},
 {175/128 + 256 y[1] - 512 y[2] + 256 y[3]},
 {4095/2048 + 256 y[2] - 512 y[3] + 256 y[4]},

I want to convert it to a matrix equation:

A*y=b

Do you have some suggestions to do it? Thanks!


Solution

  • eq = {
         975/2048 - 512 y[1] + 256 y[2],
         175/128 + 256 y[1] - 512 y[2] + 256 y[3],
         4095/2048 + 256 y[2] - 512 y[3] + 256 y[4]} 
     b = -eq /. y[_] -> 0;
     a = Transpose[Table[ D[ eq, y[i]] , {i, 4}]];
     a.Table[ y[i], {i, 4}] == b
    
     {-512 y[1] + 256 y[2],
       256 y[1] - 512 y[2] + 256 y[3], 
       256 y[2] - 512 y[3] + 256 y[4]} == 
                    {-(975/2048), -(175/128), -(4095/2048)}
    

    then to solve:

    sol = LinearSolve[a, b];
    

    {3155/524288, 5335/524288, 4715/524288, 0}

    (eq /. Table[ y[i] -> sol[[i]] , {i, 4}]) == {0, 0, 0}
    

    True