how to display on increment 0.5 for time

11 views (last 30 days)
how to only show printf only increment of 0.5? right now it's shown in increment of 0.001. its gonna long from 0 to 10.
i still need increment 0.001 for my calculation if i use 0.5. it will be different.
i just want to show a smaller set of data. rightnow, the earlier data can't be scroll.
%le1=1;
%le2=1.5;
%d=10;
%kr=25000;
%kf=20000;
%j=800;
%m=1000;
clc;
h=0.001; z=0;
v=0; x=0; x2=0;
theta=0;theta2=0;
fprintf('time\t\tx\t\ttheta\n--------------------------------------------------------------------------------\n')
maxbounce=0;
maxpitch=0;
tbounce = 0;
tpitch=0;
for t=0:0.001:10
%figure(1);
%plot(t,x,'*');
%hold all;
%figure(2);
%plot(t,theta,'*');
hold all;
j1=h*z;
k1=h*(1/1000)*(1000*sin(3*pi*t)+1250*sin(3*pi*t-0.2*pi*(2.5))-(45000)*x-(17500)*theta);
j2=h*(z+0.5*k1);
k2=h*(1/1000)*(1000*sin(3*pi*(t+0.5*h))+1250*sin(3*pi*(t+0.5*h)-0.2*pi*(2.5))-(45000)*(x+0.5*j1)-(17500)*theta);
j3=h*(z+0.5*k2);
k3=h*(1/1000)*(1000*sin(3*pi*(t+0.5*h))+1250*sin(3*pi*(t+0.5*h)-0.2*pi*(2.5))-(45000)*(x+0.5*j2)-(17500)*theta);
j4=h*(z+k3);
k4=h*(1/1000)*(1000*sin(3*pi*(t+h))+1250*sin(3*pi*(t+h)-0.2*pi*(2.5))-(45000)*(x+j3)-(17500)*theta);
x1=x+(j1+2*(j2+j3)+j4)/6;
z=z+(k1+2*(k2+k3)+k4)/6 ;
n1=h*v;
m1=h*(1/800)*(1875*sin(3*pi*t-0.5*pi)-1000*sin(3*pi*t)-17500*x-76250*theta);
n2=h*(v+0.5*m1);
m2=h*(1/800)*(1875*sin(3*pi*(t+0.5*h)-0.5*pi)-1000*sin(3*pi*(t+0.5*h))-17500*x-76250*(theta+0.5*n1));
n3=h*(v+0.5*m1);
m3=h*(1/800)*(1875*sin(3*pi*(t+0.5*h)-0.5*pi)-1000*sin(3*pi*(t+0.5*h))-17500*x-76250*(theta+0.5*n2));
n4=h*(v+m1);
m4=h*(1/800)*(1875*sin(3*pi*(t+h)-0.5*pi)-1000*sin(3*pi*(t+h))-17500*x-76250*(theta+n3));
theta1=theta+(n1+2*(n2+n3)+n4)/6;
v=v+(m1+2*(m2+m3)+m4)/6 ;
theta=theta1;
x=x1;
if(x>maxbounce)
maxbounce =x;
tbounce = t;
endif
if(theta>maxpitch)
maxpitch=theta;
tpitch=t;
endif
printf('%.4f\t\t%.6f\t\t%.4f\n',t,x1,theta1);
end
printf('Maximum value for x = %.4f at t= %d\n',maxbounce,tbounce);
printf('Maximum value for theta = %.8f at t = %d',maxpitch,tpitch);
  1 Comment
Rik
Rik on 25 Jan 2021
Edit restored from Google cache. @ihtifazuddin Nashruddin Don't edit away important parts of your question. That is extremely rude to the people helping you.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 25 Jan 2021
Change this:
for t=0:0.001:10
to:
for t=0:0.5:10
That is the only line that defines ‘t’ that I can see, so that one change should do what you want. .
  4 Comments

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 25 Jan 2021
Either create a counter that counts how many iterations you've performed and only fprintf if the counter indicates the current value of the loop variable is (close enough to) a multiple of 0.5 or use ismembertol or rem to check if the loop variable is "close enough to" a multiple of 0.5.
You do not want to simply use == or ismember as 0.01 is not exactly representable in floating point.

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!