problem related to for loop
이전 댓글 표시
I am trying to plot x and v equation for different value of m ... please take alook and kindly guid me through this
m = [10,20,30,40];
k = 50;
x0=0.01;
v0=0.2;
d=size(m);
dt = 0.001;
t = 0:dt:10;
for l=0:d
wn(l) = sqrt(k(l)/m(l));
s1(l) = 1i*sqrt(k(l)/m(l));
s2(l) = -1i*sqrt(k(l)/m(l));
C1(l) = (-v0+x0*s2(l))/(s2(l)-s1(l));
C2(l) = (v0-x0*s1(l))/(s2(l)-s1(l));
x(l) = C1(l)*exp(s1(l)*t)+C2(l)*exp(s2(l)*t);
v(l) = C1(l)*s1(l)*exp(s1(l)*t)+C2(l)*s2(l)*exp(s2(l)*t);
end
figure;
subplot(211),plot(t,x,'r--'); xlabel('Time'), ylabel('Displacement')
subplot(212),plot(t,v,'r--'); xlabel('Time'), ylabel('Displacement')
채택된 답변
추가 답변 (1개)
Chad Greene
2015년 10월 14일
0 개 추천
You can't start indexing with zero. You'll have to do for l = 1:length(m)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!