我试图在我的m文件中使用此函数但是我收到错误(提到了问题)。一切似乎都正确,a,b和c在我的m文件中定义。有什么想法吗?
错误:
Error in modal2 (line 8)
[v,an]=eig(a);
Output argument "am" (and maybe others) not assigned during call to "C:\Users\Cena\Desktop\Thesis\My Codes\SMC\modal2.m>modal2".
function [r,am,bm,cm] = modal2(a,b,c)
% this function determines the modal representation 2(am,bm,cm)
%given a generic state-space representation (a,b,c)
%and the transformation r to the modal representation
%such that am=inv(r)*a*r, bm=inv(r)*b and cm=c*r
%transformation to complex-diagonal form:
[v,an]=eig(a);
bn=inv(v)*b;
cn=c*v;
%transformation to modal form 2:
i = find(imag(diag(an))');
index = i(1:2:length(i));
j=sqrt(-1);
t = eye(length(an));
if isempty(index)
am=an;bm=bn;cm=cn;
else
for i=index
t(i:i+1,i:i+1)=[j 1;-j 1];
end
%Modal transformation
r=v*t;
end
答案 0 :(得分:1)
问题可能在
if isempty(index)
am=an;bm=bn;cm=cn;
只有在条件通过时才会对这些变量进行赋值。如果没有,则没有任务。
如果它们将成为输出参数,您需要修改代码以在所有条件下分配这些变量。