我有一些代码,特征向量数值求解:Matlab的:命令行输入的特征函数求解(数值方法)
function[efun,V,D] = solveeig(n,xmax,i)
for j=1:i
%The first and second derivative matrices
dd = 1/(xmax/n)^2*(-2*diag(ones(n,1))+diag(ones(n-1,1),1)+...
diag(ones(n-1,1),-1));
d = 1/(xmax/n)*((-1*diag(ones(n,1)))+diag(ones(n-1,1),1));
%solve for the eigenvectors
[V,D] = eig(-dd-2*d);
%plot the eigenvectors (normalized) with the normalized calculated
%eigenfunctions
x = linspace(0,xmax,n);
subplot(i,1,j);
plot(x,V(:,j)/sum(V(:,j)),'*');
hold on
efun = exp(-x).*sin(j*pi*x/xmax);
plot(x,efun/(sum(efun)),'r');
shg
end
end
我应该是第一个我的特征向量,n为维 矩阵(我们离散x片段的数量),xmax是定义fxn的范围的上限。我试图从命令行(如:“solveeig###”,其中数字符号对应于i,n和xmax)运行此命令,但不管我似乎为我放置什么, n和xmax,我得到“对于带有char操作数的冒号操作符,第一个和最后一个操作数必须是char。”
我应该在命令行写什么来让它运行?
类型的“不是你要求的”,但解决方案(#,#,#)有什么问题?另外,你的意思是在MATLAB中的命令窗口或Linux终端或DOS提示符? – patrik 2015-03-25 11:11:11