Unrecognized function or variable in Matrix element input

1 回表示 (過去 30 日間)
Tsz Tsun
Tsz Tsun 2023 年 3 月 9 日
回答済み: Aman 2023 年 3 月 13 日
Hello all, I am a very new MatLab user and I encounter an error in my code. I am writing enteries into a matrix, in which the entries are calculated by by summation and integration. It has an error of unrecognized variable "u". I have also tried to declare syms u; but it has even more serious error.
Omega = 1;
L=1;
Hamiltonian = [];
Omegak = -pi;
Vpi = 1;
V1 = 1;
T=1;
w=1;
syms t;
%Writing entries into a 5 x 5 matrix from calcuation by summation and integration
for p=1:1:5
for q=1:1:5
Hamiltonian(p,q) = p*Omega*kroneckerDelta(sym(p),sym(q)) - ((Omega*V1)/(2*T*Vpi))*symsum(exp(-i*u*Omegak)*(sin((u*w)/(2*pi*L))/((u*w)/(2*pi*L)))*int(cos(Omega*t)*exp(-i*Omega*t*(q-p-u)) ,t,0,T) ,u,0,100)
end
end
Unrecognized function or variable 'u'.
Hamiltonian(1,2)
  3 件のコメント
Tsz Tsun
Tsz Tsun 2023 年 3 月 9 日
I have tried to define u using syms u; but it gives an error message of
rSym = mupadmex('symobj::map',fsym.s,'symobj::symsum',x.s,a.s,b.s)
which I cannot understand
Jan
Jan 2023 年 3 月 9 日
Whenever you mention an error message in the forum, attach a copy of the complete message. It is easier to fix a problem than to guess, what it is.

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

回答 (1 件)

Aman
Aman 2023 年 3 月 13 日
Hi,
I understand that you have written code for performing some calculation and you are getting error of unrecognized variable. Even after declaring the variable, you are getting some other error.
In your case the unrecognized variable error can be resolved by declaring it prior to its use.
Secondly “Hamiltonian(p,q)” calculation gives division by zero error which can be fixed by putting up the proper limits. Please refer the below code where I have updated the limit from 0 to 6.
Omega = 1;
L=1;
Hamiltonian = [];
Omegak = -pi;
Vpi = 1;
V1 = 1;
T=1;
w=1;
syms t;
syms u;
%Writing entries into a 5 x 5 matrix from calcuation by summation and integration
for p=1:1:5
for q=1:1:5
Hamiltonian(p,q) = p*Omega*kroneckerDelta(sym(p),sym(q)) - ((Omega*V1)/(2*T*Vpi))*symsum(exp(-i*u*Omegak)*(sin((u*w)/(2*pi*L))/((u*w)/(2*pi*L)))*int(cos(Omega*t)*exp(-i*Omega*t*(q-p-u)) ,t,0,1) ,u,6,100);
end
end

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by