It seems that you need to subscript the appropriate variables. I’m not certain that this is what you want, but it at least has the virtue of running and plotting:
k=1000; c=50; M=200; m=2; e=0.1;
vv=[20,40,0,0.5];
w=[20:0.5:40];
for k1 = 1:length(w)
r(k1)=w(k1)*sqrt(M/k);
wn=w(k1)./r(k1);
damp=c/2/M./wn;
phi=atan((2*damp.*r(k1))./(1-r(k1).^2));
X=(m*e*r(k1))./(M*sqrt((1-r(k1).^2).^2+(2*damp.*r(k1)).^2));
F=m*e*w(k1).^2.*sin(w(k1));
dx=w(k1).*X.*cos(w(k1)-phi);
T=2*pi*w(k1);
P(k1,:)=abs(F.*dx);
end
plot(w,P,'k','linewidth',2); axis(vv); grid on; hold on;
xlabel('Forcing Frequency (Hz)', 'fontsize', 12);
title('Problem 7');
ylabel('Mean Power Output (Hp)', 'fontsize', 12);
Experiment with it to get the result you want. You likely have to move the plot call outside the loop in any event.
Best Answer