Problems with a function of matrix
4 ビュー (過去 30 日間)
古いコメントを表示
Hi I am new to matlab and I have an error when I write a function of a matrix, here is my code
function w = windingNumberCalculation(C, Delta, g, Gamma , kappa, m)
syms k;
%Define an Hamiltonian matrix
nonHermitianHamiltonian(1,1) = 2*kappa*cos(k) + 2*C*cos(2*m*k) + i*2*Delta*sin(2*m*k) - i*Gamma ;
nonHermitianHamiltonian(1,2) = g;
nonHermitianHamiltonian(2,1) = g;
nonHermitianHamiltonian(2,2) = 0;
nonHermitianHamiltonian
w= int(diff(log(det(nonHermitianHamiltonian - 0.5*trace(nonHermitianHamiltonian)*eye(2)))) ,k , 0 , 2*pi) /(2*pi*i)
end
Then I want to excute my function, for example.
windingNumberCalculation(0.052, -0.025, 0.087, 0.134,0,1)
However, I receive messages like "This statement is not inside any function.
(It follows the END that terminates the definition of the function "windingNumberCalculation".)"
But however, I don't receive any error messages if I don't use the function method for calculation, i.e . the below code runs perfectly fine
Omega= 1;
C= 0.052*Omega;
Delta = -0.025*Omega;
g= 0.087*Omega;
Gamma = 0.134*Omega;
kappa = 0*Omega;
m=1;
syms k;
%Define an Hamiltonian matrix
nonHermitianHamiltonian(1,1) = 2*kappa*cos(k) + 2*C*cos(2*m*k) + i*2*Delta*sin(2*m*k) - i*Gamma ;
nonHermitianHamiltonian(1,2) = g;
nonHermitianHamiltonian(2,1) = g;
nonHermitianHamiltonian(2,2) = 0;
nonHermitianHamiltonian;
w= int(diff(log(det(nonHermitianHamiltonian - 0.5*trace(nonHermitianHamiltonian)*eye(2)))) ,k , 0 , 2*pi) /(2*pi*i)
May I know what is the problem when using the function?
0 件のコメント
採用された回答
VBBV
2023 年 4 月 3 日
編集済み: VBBV
2023 年 4 月 3 日
Call the function from command window and not from inside the script file where you have the code
% call the function from command window
>> windingNumberCalculation(0.052, -0.025, 0.087, 0.134,0,1)
function w = windingNumberCalculation(C, Delta, g, Gamma , kappa, m)
syms k;
%Define an Hamiltonian matrix
nonHermitianHamiltonian(1,1) = 2*kappa*cos(k) + 2*C*cos(2*m*k) + i*2*Delta*sin(2*m*k) - i*Gamma ;
nonHermitianHamiltonian(1,2) = g;
nonHermitianHamiltonian(2,1) = g;
nonHermitianHamiltonian(2,2) = 0;
nonHermitianHamiltonian
w= int(diff(log(det(nonHermitianHamiltonian - 0.5*trace(nonHermitianHamiltonian)*eye(2)))) ,k , 0 , 2*pi) /(2*pi*i)
end
3 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Numerical Integration and Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!