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 件のコメント
Adam
Adam 2017 年 3 月 13 日
編集済み: Adam 2017 年 3 月 13 日
I don't use the symbolic toolbox, but I'm pretty sure what it isn't happy about you using
syms k
in the definition of the eye matrix. I don't know what syms k is, but I assume it isn't numeric.
Jan
Jan 2017 年 3 月 13 日
Welcome in the forum. Please start with reading this.

サインインしてコメントする。

回答 (1 件)

Brandon Eidson
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 ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by