What next in the code
显示 更早的评论
While running the code
%NATURAL FREQUENCIES AND MODE SHAPES FOR A 4 STOREY BUILDING
k=[71284.72 -35642.36 0 0;-35642.36 71284.72 -35642.36 0;0 -35642.36 71284.72 -35642.36;0 0 -35642.36 35642.36];
m=[632.25 0 0 0;0 632.25 0 0;0 0 632.25 0;0 0 0 363.75];
W=Naturalfreq(k,m)%Function 1
X=zeros(4,4);
for i=1:4
Y=Modeshape1(W(5-i),k,m); %Function 2
X(:,i)=Y;
plot(X)
end
Function 1
[W] = Naturalfreq(k,m)
syms omega
a = k-(omega*m);
b = det(a);
c = sym2poly(b);
d = roots(c);
W = sqrt(d);
Function 2
[X] = Modeshape1(W,k,m)
omega = W^2;
a = k - (omega*m);
x1 = 1;
x2 = -a(1,1)/a(1,2);
x3 = -(a(2,1)+a(2,2)*x2)/a(2,3);
x4 = -(a(3,2)*x2+a(3,3)*x3)/a(3,4);
X = [x1;x2;x3;x4]
The following error occurs
Undefined function or variable 'Naturalfreq'.
Error in
W=Naturalfreq(k,m)%Function 1
采纳的回答
更多回答(1 个)
Your function definitions are not correct. Instead of this invented syntax:
Function 1
[W] = Naturalfreq(k,m)
... your code
function W = Naturalfreq(k,m)
... your code
end % you need this too!
I highly recommend that you read about how to include functions into scripts:
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!