我试图在我的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发布于 2015-06-14 21:35:05
问题很可能出现在
if isempty(index)
am=an;bm=bn;cm=cn;只有在条件通过的情况下,才会对这些变量进行赋值。如果没有,就没有赋值。
如果要将这些变量作为输出参数,则需要修改代码以在所有条件下将其赋值给这些变量。
https://stackoverflow.com/questions/30827993
复制相似问题