disp(' Please specify the init ial angle from the')
disp(' verti cal upright position . ')
disp(' ')
offset=input ( 'Enter the initial angle now : ');
tfinal=input ( ' Please enter the duration of simulation: ' ) ;
disp ( ' I am working .... ' )
theta = pi-offset ;
thetadot = 0;
dt =.2; t=0 ; tf=tfinal ;
disp ( ' Watch the graphics screen ' )
clf
hl = axes('position',[0.55 .1 .4 .3]);
axis( [0 tf -4 4] );
xlabel( 'time') , ylabel('displacement ')
Displ = line('xdata' , [] , 'ydata' , [] , 'marker','.' , 'erasemode' , 'none' );
h2 = axes( 'position' , [0.55 .55 .4 .3]);
axis ( [0 tf -4 4] ) ;
xlabel ( ' t ime') , ylabel ('velocity ')
Vel = line ( 'xdata' , [] , 'ydata' , [] , 'marker' , '.' , 'erasemode' , 'none' ) ;
h3 = axes( 'position',[.1 .1 .4 .4]);
axis ( [-pi pi -4 4] )
axis ('square')
xlabel ( 'displacement' ) , ylabel ( 'velocity')
Phase = line('xdata' , [] , 'ydata' , [] , 'marker' , '.' , 'erasemode' , 'none' ) ;
h4 = axes ( 'position' , [.1 .55 .4 .4]);
axis ( [-2 2 -2 2] )
axis ( 'square' )
data = [0 0; - 1.8 0] ;
phi = 0;
R = [cos(phi) -sin(phi ) ; +sin(phi ) cos(phi)] ;
data=R*data;
bar = line('xdata' , data (1, :), 'ydata' , data (2, :),...
'linewidth' ,3, 'erase' , 'xor') ;
hinge = line( 'xdata' , 0 , 'ydata' , 0 , 'marker' , 'o' , 'markersize' , [10] ) ;
path = line( 'xdata' , [] , 'ydata' , [] , 'marker' , '.' , 'erasemode' , 'none' ) ;
while (t<tfinal )
end
t = t+dt ;
theta = theta + thetadot*dt ;
thetadot = thetadot -sin(theta) *dt ;
R = [cos(theta) ( -sin(theta) ); sin(theta) cos(theta) ];
datanew = R*data;
set (path , ' xdata ', datanew( 1,1 ), 'ydata ', datanew( 2 , 1 ) ) ;
set (bar , 'xdata' , datanew (1, :), 'ydata' , datanew (2, :) );
set (Phase , 'xdata ', theta, 'ydata ', thetadot );
set (Displ , 'xdata', t, 'ydata' , theta ) ;
set (Vel , 'xdata' , t, 'ydata' , thetadot ) ;
drawnow ;
0 Comments
Sign in to comment.