How do I include a variable inside an identity matrix so that i can sum up a tensor multiplication including the identity matrices?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Brandon Eidson
am 16 Mär. 2017
Bearbeitet: Brandon Eidson
am 16 Mär. 2017
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.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!