我试图在x轴上绘制变量x的值值图表;但是,每个点有三个值,也就是说,固有频率1,固有频率2和固有频率3。 这是代码,它不起作用:
M = [3 0 0; 0 2 0; 0 0 0.5]
% disp('Mass matrix [M]');
% disp(M);
for i=1:1000:60e06
K = [i+7e06 i -6e06; i i+3e06 -3e06; -6e06 -3e06 10e06];
% disp(K)
[V,L]=eig(K,M); % eig is a standard Matlab function
values=diag(L); % diag gets the values from the leading diagonal
[values,I]=sort(values); % sort into ascending order of frequency
V(:,I)=V; % now sort the mode shape vectors
freq=sqrt(values)/(2*pi); % this divides all elements by 2 pi
% disp('Eigenvalues [s^(-2)]');
% disp(values'); % the quote mark after values prints the column vector as a row
% disp('Frequencies [Hz]');
% disp(freq');
% disp('Mode shape vectors in the columns of matrix [V]');
% disp(V);
loglog(i, freq(1:1), i, freq(2:1), i, freq(3:1)
end
为错误道歉,我是初学者。
答案 0 :(得分:2)
您缺少行尾的结束括号
loglog(i, freq(1:1), i, freq(2:1), i, freq(3:1)
此外,我没有看到您2:1
,3:1
,...的原因?...
将其替换为
loglog(i, freq(1), i, freq(2), i, freq(3))
我认为你的阴谋没有任何问题。
一般情况下,我建议将 freq 的值存储在某个数组中并单独绘制。这会使脚本加速很多,即
%preallocate freq, the number of iterations in the loop is important here
freq = zeros(3,length(1:1e3:60e6))
for i = ...
%your loop goes here
%remove freq = ...
%remove loglog( ...
freq(:,i) = sqrt(values)/(2*pi); % this divides all elements by 2 pi
end
loglog(1:1e3:60e6, freq(1,:)) %plot first curve
loglog(1:1e3:60e6, freq(2,:)) %plot second curve
loglog(1:1e3:60e6, freq(3,:)) %plot third curve
答案 1 :(得分:2)
你的问题是你在循环中有loglog
。
在循环之前,我把:
i_vals = 1:1000:60e06;
freq = zeros(3, length(i_vals));
我将循环的顶部更改为:
for n=1:length(i_vals)
i = i_vals(n);
K = [i+7e06 i -6e06; i i+3e06 -3e06; -6e06 -3e06 10e06];
...
同时更改freq
作业:
freq(:, n)=sqrt(values)/(2*pi);
删除loglog
并将其放在循环之后/之外。
loglog(i_vals, freq')
所有这一切都给了我这个: