在Scilab中错误定义了子矩阵 [英] Submatrix incorrectly defined in Scilab

查看:192
本文介绍了在Scilab中错误定义了子矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个莫尔斯电势,可以通过scilab求解并找到其能量本征值和向量.但是我遇到了一个问题,因为scilab表示子矩阵定义不正确.

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)

推荐答案

您将名称h用于两个不同的变量(标量和矩阵),这就是计算失败的原因.顺便说一句,您正在使用许多无用的括号(这无助于阅读您的代码).每次引用矩阵并在其中定义行之后,都可以用大写字母H安全地替换h:

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)

这篇关于在Scilab中错误定义了子矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆