在计算特征向量/绘制图形时,Matlab突然从正值变为负值(一个bug?)

时间:2013-12-12 21:07:14

标签: matlab graph linear-algebra eigenvector

我在你的帮助下写了以下代码:

M = [3  0  0.0; 
     0  2  0.0; 
     0  0  0.5];   % mass matrix

i_vals = 0:1000:60e06;   % values of k_12 from 1 to 600 million in steps of 1000
modes = zeros(3, length(i_vals));

for n=1:length(i_vals)
    i = i_vals(n);    % i is the value of k_12
    K = [i+8e06 -i -2e06; -i i+2e06 -1e06; -2e06 -1e06 5e06];    % stiffness matrix

    [V,L]=eig(K,M);         

    modes(:, n) = V(:,1); % natural frequency can be either 1, 2 or 3

end

semilogx(i_vals, modes')
    title('Effect of change of value of k_1_2 on the value of mode shapes for the first natural frequency');
    xlabel('Value of k_1_2 [N/m]');
    ylabel('Value of mode shapes]');
    hleg1 = legend('mode shape 1','mode shape 2', 'mode shape 3');
    grid on;
    grid minor;

问题在于某些值Matlab突然从正值切换到负值: image

这是否归因于eig()功能?怎么可能解决它?

1 个答案:

答案 0 :(得分:2)

特征向量总是确定为符号,因为将特征向量乘以-1不会改变其作为特征向量的状态。您可以尝试使用FEX中的eigenshuffle