How do I include a variable inside an identity matrix so that i can sum up a tensor multiplication including the identity matrices?
5 次查看(过去 30 天)
显示 更早的评论
Hi, I'm having a little trouble in Matlab right now! What I am trying to do is write a generic formula to solve the Hamiltonian of a Spin Chain of length X (any length hence the generic part).
The code I am currently working with is as follows:
L=5
syms k
J = symsm([kron(eye(k),kron(A,kron(A,eye(L-k-2))))], k, 0, L-2)
%I am using a value of L just to try and get the code to work for a given example
The error that I get is:
Error using eye
Size inputs must be numeric.
Error in group_project (line 55)
J = symsm([kron(eye(k),kron(A,kron(A,eye(L-k-2))))], k, 0, 3)
I think Matlab isn't happy that I'm putting a variable for the size of the identity matrix, but I'm at a loss for what I should do because that is solvable by manual computation by hand.
This is my first post, would love it if anybody could help!
Thanks, Aaron.
2 个评论
回答(1 个)
Brandon Eidson
2017-3-16
编辑:Brandon Eidson
2017-3-16
Hey Aaron, your question is an interesting one. I understand that you are trying to come up with a symbolic solution for a variable "k", where "k" is the size of a square matrix. If I understand you correctly, I do not think you can accomplish precisely what you want using MATLAB.
Firstly, the "eye" function cannot take a symbolic variable as an argument. As the error states, the input arguments must be numerics (the "eye" function's documentation is linked to below).
Secondly, one cannot work with a matrix in MATLAB (or any other software of which I am aware) that has an unknown dimension size. Specifically, although one can have a matrix of symbolic variables, one cannot have a symbolically-sized matrix.
I think your best option is to create a MATLAB function with "L" and "k" as arguments. You can then pass large ranges of values of "k" to the function and analyze the various solutions versus "k". You can use a function like "fsolve" if your equation is nonlinear (documentation linked to below).
One last note: "symsm" is not a shipped MATLAB function. Please review this if "symsm" is not a custom function you created.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Algebra 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!