【发布时间】:2017-08-08 13:54:21
【问题描述】:
运行代码时出现此错误:
错误使用 ==> mldivide 矩阵维度必须一致。
这是我的代码:
%make the plots of phase and group velocity vs discreteness of the grid
c=1;
a=input('Please enter the ratio cdt/dx : ')
figure(1)
R=2:40;
plot(R,phase_vel(R,a)/c)
xlabel('R=l/dx')
ylabel('u_phase/c')
%figure(2)
%plot(group_vel(R,a),R,0,40)
%xlabel('R=l/dx')
%ylabel('u_group/c')
这是我的功能:
function phase_velocity = phase_vel(R,a)
%numerical phase velocity of the discrete wave
c=1;
phase_velocity=(2*pi*c)/(R*knum(R,a));
end
function group_velocity =group_vel(R,a )
%numerical group velocity of the discrete wave
c=1;
group_velocity=(a*sin(knum(R,a)))/(sin(2*pi*a/R))
end
function knumber = knum(R,a)
%This is the k wave number
knumber=acos((1/a)^2*(cos(2*pi*a/R)-1)+1);
end
我该如何解决这个错误?
编辑:我用过 .每个方程中的运算符,我改变了 R=4:40 的限制
【问题讨论】:
-
我没有符号数学工具箱,看起来你正在使用它,所以以下问题可能一无所知:(1)是在第一个
plot还是第二个你得到错误了吗? (2) 如果第一个可以,第二个不行,如果你说omega=2*pi/R/dt;而不是omega*dt==2*pi/R;,这样那里没有方程求解会有帮助吗? -
您提供了很多行代码,如果知道您的代码在哪个函数的哪一行失败,将会非常很有帮助。
-
您好,问题出在第一个脚本的 plot 命令(第一个情节)中。两个情节都给我同样的错误。(我试过 omega=2*pi/R*dt,但是还是一样)