4. MATLAB Code for Wild Wild West
%input-output relationships
rin= 2.3; %cm
rout=6.9; %cm
N1=6;
N2=12;
win(1)=0;
vin(1)=0;
for i=1:10
wout(i)=win(i)*N1/N2;
vout(i)=rout*N1*vin(i)/rin/N2;
win(i+1)=win(i)+1;
vin(i+1)=vin(i)+1;
end
figure
plot(win(1:10),wout)
xlabel("input angular velocity (rad/s)")
ylabel("output angular velocity (rad/s)")
figure
plot(vin(1:10),vout)
xlabel("input linear velocity (m/s)")
ylabel("output linear velocity (m/s)")
%input-output versus time
rin= 2.3; %cm
rout=6.9; %cm
routnew=2.3; %cm
N1=6;
N2=12;
%
win(1)=0; %rad/s
thetain(1)=0;
t(1)=0;
ain=0.1; %rad/s^2 constant acceleration
for i=1:101
thetain(i)=win(1)*t(i)+0.5*ain*t(i)^2;
thetaout(i)=0.5*thetain(i);
traindistance(i)=rout*thetaout(i);
traindistancenew(i)=routnew*thetaout(i);
inputdistance(i)=rin*thetain(i);
win(i)=win(1)+ain*t(i);
wout(i)=0.5*win(i);
vin(i)=rin*win(i);
vout(i)=rout*N1*vin(i)/rin/N2;
voutnew(i)=routnew*N1*vin(i)/rin/N2;
t(i+1)=t(i)+1;
end
figure
plot(t(1:101),vout)
xlabel("time (s)")
ylabel("magnitude of velocity (cm/s)")
hold on
plot(t(1:101),vin)
Welcome to the University Wiki Service! Please use your IID (yourEID@eid.utexas.edu) when prompted for your email address during login or click here to enter your EID. If you are experiencing any issues loading content on pages, please try these steps to clear your browser cache.