Question

In: Mechanical Engineering

Write Matlab code and run them for the following: a) Motion of a point in a...

Write Matlab code and run them for the following:

a) Motion of a point in a circle

b) Motion of a line in a circle

c) Motion of slider crank mechanism

Solutions

Expert Solution

a)

radius=[10 15 20 30]
velocity=[5 2.5 15 20]
colors=['y','m','c','r'] % This is to just make the points different colors

p=zeros(4,1); %here we will store the handles to delete the point
hold on
for i=1:4 %Loop to create multiple circles
th=0:pi/50:2*pi;
xunit=radius(i)*cos(th);
yunit=radius(i)*sin(th);
h=plot(xunit,yunit);
p(i)=plot(xunit(1),yunit(1),'o','MarkerFaceColor',colors(i),'Color',colors(i));
%creates a point on each graph
end

time=[0:0.001:100]; %time vector in seconds

for t=1:length(time)
for i=1:4 %Loop to create multiple circles
delete(p(i)); %delete the old point
%computes the new angle for each point as velocity*time
xunit=radius(i)*cos(velocity(i)*time(t));
yunit=radius(i)*sin(velocity(i)*time(t));
%creates a point on each graph
p(i)=plot(xunit(1),yunit(1),'o','MarkerFaceColor',colors(i),'Color',colors(i));   
end
pause(0.01); %wait 0.01 seconds so the plot is displayed
end

hold off
b)

pC = [4; 10]; % initial position of A
vC = [2.3100; -0.5500]; % initial velocity of A
dt = 0.1; % time step for animation
clf; % Clear the figure
axis(50*[0 1 0 1],'square'); % Set axis limits
grid on;
hold on; % Keep plot from erasing
for t=0:dt:15 % t is time variable
plot(pC(1),pC(2),'ro') % Plot circle
pC = pC + vC*dt; % update position
pause(dt) % pause for animation
end
hold off;
title('Motion animation');
xlabel('x (m)');  
ylabel('y (m)');

C)

close all
clear all
% Analysis of a slider-crank mechanism
%Section 1: Input data and prepare problem
r1=0; %ground
r2=1;%crank shaft
r3=2;%connecting rod
h=0.5;%offset
%fixed link angle is zero
theta10=0;
% Initialize joints
joint(1).type = 'r';% Revolute
joint(1).memb =[1 2];% Between member 1 and 2
joint(2).type = 'r'; % Revolute
joint(2).memb = [2 3]; % Between member 2 and 3
joint(3).type = 'r'; % Revolute
joint(3).memb =[3 4]; % Between member 3 and 4
joint(4).type = 'p'; % Prismatic
joint(4).memb = [4 1]; % Between member 4 and 1
%Initial Guess
theta20=45;
theta30=-10;
theta40=0;
R1x0=0;
R1y0=0;
R2x0=(r2/2)*cosd(theta20);
R2y0=(r2/2)*sind(theta20);
R3x0=(r2)*cosd(theta20)+(r3/2)*cosd(theta30);
R3y0=(r2)*sind(theta20)+(r3/2)*sind(theta30);
R4x0=(r2)*cosd(theta20)+(r3)*cosd(theta30);
R4y0=(r2)*sind(theta20)+(r3/2)*sind(theta30);
%input parameters
t(1)=0;
dt=0.1;%seconds
omega2=1; % input velocity (rad/s)
imax=10; %number of time steps
converge=0;
epsilon1=0.001; %dtheta accuracy
epsilon2=0.001;%C accuracy
%Define the local position vectors
u1O=[0;0];
u2O=[-r2/2;0];
u2A=[r2/2;0];
u3A=[-r3/2;0];
u3B=[r3/2;0];
u4B=[0;0];
u4C=[0;0];
u1C=[0;h];

%Initialize variables
Rx(1:4,1:imax)=0;
Ry(1:4,1:imax)=0;
theta(1:4,1:imax)=0;
Rxd(1:4,1:imax)=0;
Ryd(1:4,1:imax)=0;
thetad(1:4,1:imax)=0;
Rxdd(1:4,1:imax)=0;
Rydd(1:4,1:imax)=0;
thetadd(1:4,1:imax)=0;
%Section 2: Position Analysis
i=1;
while i<=imax
t(i)=(i)*dt;

%input motion
theta(2,i)=theta20+omega2*t(i)*(180/pi);

%adjust initial conditions based on the step #
if i==1
Rx(2,i)=R2x0;
Ry(2,i)=R2y0;
theta(2,i)=theta20;
Rx(3,i)=R3x0;
Ry(3,i)=R3y0;
theta(3,i)=theta30;
Rx(4,i)=R4x0;
Ry(4,i)=R4y0;
theta(4,i)=theta40;
else
Rx(2,i)=Rx(2,i-1);
Ry(2,i)=Ry(2,i-1);
theta(2,i)=theta(2,i-1);
Rx(3,i)=Rx(3,i-1);
Ry(3,i)=Ry(3,i-1);
theta(3,i)=theta(3,i-1);
Rx(4,i)=Rx(i-1);
Ry(4,i)=Ry(i-1);
theta(4,i)=theta(4,i-1);
end;


Related Solutions

Please write a MATLAB code that shows the intersection point of resistance circle and reactance arc...
Please write a MATLAB code that shows the intersection point of resistance circle and reactance arc on Smith Graph, according to the given load impedance value. Assuming that the characteristic impedance of the transmission line is taken as 50 ohms.
Write the following MATLAB functions. Run it on an example and test it and confirm that...
Write the following MATLAB functions. Run it on an example and test it and confirm that it gives correct results. Show all results. function x=naivege(a,b) that returns the solution to Ax=b obtained by Gauss Elimination without pivoting
Write a C or Matlab code for E11(1, 6), consider the point G = (2, 7)....
Write a C or Matlab code for E11(1, 6), consider the point G = (2, 7). Compute the multiples of G from 2G through 13G
Use Matlab to write the following 1. Write code to determine whether a year is a...
Use Matlab to write the following 1. Write code to determine whether a year is a leap year. Use the mod function. The rules for determining leap years in the Gregorian calendar are as follows: All years evenly divisible by 400 are leap years. Years evenly divisible by 100, but not by 400, are not leap years. Years divisible by 4, but not by 100, are leap years. All other years are not leap years. For example, the years 1800,...
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio...
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds), takes Fourier transform of the signal (probably FFT).
write a matlab code to simulate fiber optics communication system on matlab simulink
write a matlab code to simulate fiber optics communication system on matlab simulink
I'm new in MATLAB and I have to write a code in MATLAB which converts a...
I'm new in MATLAB and I have to write a code in MATLAB which converts a number from one base to another without using base2base, etc
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your...
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution. Develop three functions for temperature-conversion. Create a function called F_to_K that converts and return temperatures in Fahrenheit to Kelvin and store results in ‘F_to_K2.txt’. Create a function called C_to_R that converts and return temperatures in Celsius to Rankine and store results in ‘C_to_R2.txt’. Create a function called C_to_F that...
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your...
Write a MATLAB code to obtain the following. Keep your code commented whenever required. Copy your source code and command widow outcomes and screen shots of any plots in your solution. Write a user defined function ‘My_FunctionGen’. It accepts, the time vector ‘t’ with 8000 uniformly spaced values within the range of 0 to 8, Frequecy scalars ‘f1<100H’ and ‘f2<80Hz’ and Amplitude scalars ‘A1’, ‘A2’ and ‘A3’ as input arguments. It delivers x1, x2 and x3 and x4 as outputs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT