问题
I am given a morse potential to solve and to find its energy eigen values and vector by scilab. But i am having an issue as scilab is saying submatrix defined incorrectly.
I am trying to see why my matrix is unable to be correct. I am new to this platform.
De=4.618;
b=18.118;
x=0.1275;
a=0.35;
hc=197.327;
mu=912847000;
N=45;
c=(De/(2*a*b));
d=exp(2*b*(x-a));
e=exp(2*b*x);
i=exp(b*x);
f=(2*De/(a*b));
g=((a*b)^(2));
h=(De*a*b/(2));
h=zeros(N,N);
s=eye(N,N);
for n=1:N
h(n,n)=(((n*%pi*hc)^2)/(2*mu*a^(2)))+De-(c*d)+(c*e)+(f*d)-(f*e)-((h*(e-d))/(g+(%pi^(2)*n^(2))))+4*((h*(e-d))/(g+(4*(%pi^(2)*n^(2)))));
for m=n+1:N
h(m,n)=4*h*(1-(exp(-2*b*a)*((-1)^(m+n))))*e*((1/(4*g+(((m-n)^(2))*%pi^2)))-(1/(4*g+(((m+n)^(2))*%pi^2))))+4*h*i*(1-(exp(-1*b*a)*((-1)^(m+n))))*e*((1/(g+(((m+n)^(2))*%pi^2)))-(1/(g+(((m-n)^(2))*%pi^2))))
h(n,m)=h(m,n);
end
end
[al,bl,R]=spec(h,s);
el=al./bl;
e=R;
[el,k]=gsort(el)
disp(h);
disp(el)
回答1:
You are using the name h
for two different variables (a scalar and a matrix), that's why the computation fails. BTW, you are using many useless parenthesis (it does not help to read your code). You can safely replace h
by capital H
each time you refer to the matrix after and including the line where you define it:
H=zeros(N,N);
s=eye(N,N);
for n=1:N
H(n,n)=(((n*%pi*hc)^2)/(2*mu*a^(2)))+De-(c*d)+(c*e)+(f*d)-(f*e)-((h*(e-d))/(g+(%pi^(2)*n^(2))))+4*((h*(e-d))/(g+(4*(%pi^(2)*n^(2)))));
for m=n+1:N
H(m,n)=4*h*(1-(exp(-2*b*a)*((-1)^(m+n))))*e*((1/(4*g+(((m-n)^(2))*%pi^2)))-(1/(4*g+(((m+n)^(2))*%pi^2))))+4*h*i*(1-(exp(-1*b*a)*((-1)^(m+n))))*e*((1/(g+(((m+n)^(2))*%pi^2)))-(1/(g+(((m-n)^(2))*%pi^2))))
H(n,m)=H(m,n);
end
end
[al,bl,R]=spec(H,s);
el=al./bl;
e=R;
[el,k]=gsort(el)
disp(H);
disp(el)
来源:https://stackoverflow.com/questions/57815134/submatrix-incorrectly-defined-in-scilab