Want to limit the lines of output. (for example, output after every 1000 iterations)
Show older comments
time = 0;
tstop=input('enter tstop now');
m=input('enter value of m now');
k= input('enter value of k now');
b= input('enter b value now');
dt=input(' enter value of time step now');
nstep=input('enter value of nstep');
pos=input('enter starting position now');
vel=input('enter starting velocity now');
i=1;
j=1;
while time < tstop
t(i) = time;
xdot(i) = vel;
x(i) = pos;
acc= -(k/m)*pos -(b/m)*vel;
x2dot(i)=acc;
vel = vel + acc*dt;
pos = pos + vel*dt;
time = time+dt;
i=i+1;
end
out=[t',x2dot',xdot',x']
1 Comment
Image Analyst
on 27 Nov 2011
Why is "out" outside your loop? Do you want to break out of the loop when i = 1000? If you want to continue the loop you should put it inside the loop like Sven showed you.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!