![]() However, if you have defined the matrix by declaring all of its entries to be symbols, there does not seem to be a need to use this method, and a simple * can be used for multiplication and for addition. For instance, if I were to declare and to be two arbitrary matrices and wanted, for instance, to multiply them, I would use D = sym.MatrixSymbol('D', 5, 5)Īnd we would be able to see the symbolic entries of this matrix by using X = sym.MatMul(D,E) In SymPy, you should distinguish between operations involving symbolic matrices and usual operations between matrices. ) Here is one of the first things that tripped me up. (The final part of the last line is simply how we compute the inverse of. Next, let us define some function with which to work: def matrixfunction(A,B,C,t): The last two lines have no effect on the calculations, but they do give the option of displaying your matrices very nicely. First, let us state the preamble: import sympy as sym This turned out to be the key to the whole thing. I needed a way to iteratively declare each entry of the matrix as a symbol, whilst putting them together as a single matrix. Now, defining a matrix symbol in SymPy is easy, but this did not help me in solving for the matrix, and I kept getting an empty output. ![]() In order to solve an equation in SymPy, you have to declare the “symbols” that you are solving for. There is a function, and we want to find the entries of for which There is some constant which can be varied (this forms part of an iterative scheme), and an unknown matrix, which is represented purely symbolically, as such: In other words, suppose we are given matrices and, which are determined beforehand. What I am interested in is taking a bunch of given matrices (with numerical values) and constants, performing some operations with an unknown matrix, and setting each entry of the final matrix equal to zero and solving. There is a lot out there on how to use SymPy to solve matrix equations of the form. So, I am sharing what I have learned here to help someone else avoid the rather large number of internet searches I had to do to piece it together. I have been trying to do some (relatively simple) matrix calculations, and it has taking me an embarrassingly long time to figure out how to do this. I am no Python expert, and have only recently encountered SymPy, for symbolic calculations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |