SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
Exercise 5: Write a generalized code to generate a line between the given two end
points using DDA line algorithm (accommodate all the four + four conditions as
discussed in the theory class).
CODE:
clc;
clear all;
X_0 = input('X_0: ');
Y_0 = input ('Y_0: ');
X_1 = input('X_1: ');
Y_1 = input('Y_1: ');
dX = abs(X_0 - X_1);
dY = abs(Y_0 - Y_1);
sx = sign(X_1-X_0);
sy = sign(Y_1-Y_0);
n = max(dY,dX);
X(1) = X_0; Y(1) = Y_0; j=1;
for i=0:1:n
if (X_1==X)&(Y_1==Y)
break
end
j=j+1;
X(j) = X(j-1)+(dX/n)*sx;
Y(j) = Y(j-1)+(dY/n)*sy;
end
plot(round(X),round(Y));
OUTPUT:
X_0: -3
Y_0: 5
X_1: 6
Y_1: -8
Exercise 6: Write a generalized code to generate a line between the given two end
points using Bresenhams’ algorithm.
CODE:
clc;
clear all;
enter='X1: '
x1=input(enter);
enter='Y1: '
y1=input(enter);
enter='X2: '
x2=input(enter);
enter='Y2: '
y2=input(enter);
dx=abs(x2-x1);
dy=abs(y2-y1);
p=(2*dy)-dx;
i=1;
if(x1>x2)
x=x2;
y=y2;
xEnd=x1;
temp=x2;
else
x=x1;
y=y1;
xEnd=x2;
temp=x1;
end
a=zeros(abs(xEnd-temp),1);
b=zeros(abs(xEnd-temp),1);
a(1,1)=(x);
b(1,1)=(y);
while x<xEnd
x=x+1;
i=i+1;
a(i,1)=round(x);
if p<0
p=p+2*dy;
b(i,1)=round(y);
else
if((y2-y1)/(x2-x1))>0
y=y+1;
else
y=y-1;
end
p=p+(2*(dy-dx));
b(i,1)=y;
end
plot(a,b)
end
OUTPUT:
X1: 2
Y1: 6
X2: 9
Y2: 11
Exercise 7: Write a generalized code to generate a circle for a user specified radius and
coordinates of center point.
CODE:
clc;
clear all;
close all;
x1=input('x_centre: ');
y1=input('y_centre: ');
R=input('Radius: ');
x=0;
y=R;
p=1-R;
m=[x,y];
while(x<y)
x=x+1
if(p<0)
p=p+2*x+1
else
y=y-1
p=p+2*(x-y)+1
end
m=[m;x y]
end
m;
x=m(:,1);
y=m(:,2);
x2=x1+x;
y2=y1+y;
x3=x1-x;
y3=y1+y;
x4=x1+x;
y4=y1-y;
x5=x1-x;
y5=y1-y;
x6=x1+y;
y6=y1+x;
x7=x1-y;
y7=y1+x;
x8=x1+y;
y8=y1-x;
x9=x1-y;
y9=y1-x;
plot(x2,y2)
hold on
plot(x3,y3)
hold on
plot(x4,y4)
hold on
plot(x5,y5)
hold on
plot(x6,y6)
hold on
plot(x7,y7)
hold on
plot(x8,y8)
hold on
plot(x9,y9)
OUTPUT:
x_centre: 5
y_centre: 3
Radius: 8
x = 1
p = -4
m = 0 8
1 8
x = 2
p = 1
m = 0 8
1 8
2 8
x = 3
y = 7
p = -6
m = 0 8
1 8
2 8
3 7
x = 4
p = 3
m = 0 8
1 8
2 8
3 7
4 7
x = 5
y = 6
p = 2
m = 0 8
1 8
2 8
3 7
4 7
5 6
x = 6
y = 5
p = 5
m = 0 8
1 8
2 8
3 7
4 7
5 6
6 5
Exercise 8. Write a generalized code to perform a 2D translation on user specified
points (For line, triangle, and quadrilateral). Plot the figures before and after
transformation.
CODE:
clear all;
close all;
n= input('enter number of points of the figure= ');
tx= input('insert the value of translation in x direction= ');
ty= input('insert the value of translation in y direction= ');
for i=1:n
x(i)= input('insert initial x co-ordinate of point= ');
y(i)= input('insert initial y co-ordinate of point= ');
P(i,1)= [x(i)];
P(i,2)= [y(i)];
P(i,3)= [1];
end
P(n+1,1)=P(1,1);
P(n+1,2)=P(1,2);
P(n+1,3)= [1];
A= [1 0 0; 0 1 0;tx ty 1];
B= P*A;
B(n+1,1)=B(1,1);
B(n+1,2)=B(1,2);
B(n+1,3)= [1];
plot(P(:,1),P(:,2));
hold on;
plot(B(:,1),B(:,2));
OUTPUT:
enter number of points of the figure= 4
insert the value of translation in x direction= 5
insert the value of translation in y direction= 6
insert initial x co-ordinate of point= 2
insert initial y co-ordinate of point= 2
insert initial x co-ordinate of point= 4
insert initial y co-ordinate of point= 3
insert initial x co-ordinate of point= 8
insert initial y co-ordinate of point= 9
insert initial x co-ordinate of point= 7
insert initial y co-ordinate of point= -3
8a. Demonstrate Scaling, Reflection and Rotation about the coordinate axes.
clc;
clear all;
close all;
w= input('Select type of transformation(1=scaling,2=reflection about
xaxis,3=reflection about y-axis,4=rotation)=')
switch w
case 1
n= input('enter number of points of the figure= ');
ax= input('insert the value of scaling in x direction= ');
dy= input('insert the value of scaling in y direction= ');
for i=1:n
x(i)= input('insert initial x co-ordinate of point= ');
y(i)= input('insert initial y co-ordinate of point= ');
P(i,1)= [x(i)];
P(i,2)= [y(i)];
P(i,3)= [1];
end
P(n+1,1)=P(1,1);
P(n+1,2)=P(1,2);
P(n+1,3)= [1];
A= [ax 0 0; 0 dy 0;0 0 1];
B= P*A;
B(n+1,1)=B(1,1);
B(n+1,2)=B(1,2);
B(n+1,3)= [1];
plot(P(:,1),P(:,2));
hold on;
plot(B(:,1),B(:,2));
case 2
n= input('enter number of points of the figure= ');
for i=1:n
x(i)= input('insert initial x co-ordinate of point= ');
y(i)= input('insert initial y co-ordinate of point= ');
P(i,1)= [x(i)];
P(i,2)= [y(i)];
P(i,3)= [1];
end
P(n+1,1)=P(1,1);
P(n+1,2)=P(1,2);
P(n+1,3)= [1];
A= [1 0 0; 0 -1 0;0 0 1];
B= P*A;
B(n+1,1)=B(1,1);
B(n+1,2)=B(1,2);
B(n+1,3)= [1];
plot(P(:,1),P(:,2));
hold on;
plot(B(:,1),B(:,2));
case 3
n= input('enter number of points of the figure= ');
for i=1:n
x(i)= input('insert initial x co-ordinate of point= ');
y(i)= input('insert initial y co-ordinate of point= ');
P(i,1)= [x(i)];
P(i,2)= [y(i)];
P(i,3)= [1];
end
P(n+1,1)=P(1,1);
P(n+1,2)=P(1,2);
P(n+1,3)= [1];
A= [-1 0 0; 0 1 0;0 0 1];
B= P*A;
B(n+1,1)=B(1,1);
B(n+1,2)=B(1,2);
B(n+1,3)= [1];
plot(P(:,1),P(:,2));
hold on;
plot(B(:,1),B(:,2));
case 4
n= input('enter number of points of the figure= ');
o= input('enter the angle of rotation= ')
for i=1:n
x(i)= input('insert initial x co-ordinate of point= ');
y(i)= input('insert initial y co-ordinate of point= ');
P(i,1)= [x(i)];
P(i,2)= [y(i)];
P(i,3)= [1];
end
P(n+1,1)=P(1,1);
P(n+1,2)=P(1,2);
P(n+1,3)= [1];
A= [1 0 0; 0 1 0;tx
ty 1];
B= P*A;
B(n+1,1)=B(1,1);
B(n+1,2)=B(1,2);
B(n+1,3)= [1];
plot(P(:,1),P(:,2));
hold on;
plot(B(:,1),B(:,2));
end
OUTPUT:
Select type of
transformation(1=scaling,2=reflection about xaxis,3=reflection about
y-axis,4=rotation)=1
enter number of points of the figure= 4
insert the value of scaling in x direction= 3
insert the value of scaling in y direction= 2
insert initial x co-ordinate of point= 2
insert initial y co-ordinate of point= 2
insert initial x co-ordinate of point= -3
insert initial y co-ordinate of point= 6
insert initial x co-ordinate of point= 5
insert initial y co-ordinate of point= 6
insert initial x co-ordinate of point= 9
insert initial y co-ordinate of point= 11
Exercise 9: Write a generalized code to perform a 2D Rotation about an user specified
point on user specified entities (For line, triangle, and quadrilateral). Plot the figures
before and after transformation.
CODE:
clc;
clear all;
close all;
n=input('enter no of points on the figure ');
a=input('enter x coordinate o point about which entity is to be
rotated');
b=input('enter y coordinate o point about which entity is to be
rotated');
p=zeros(n,3);
for i=1:n
x(i)=input('enter x co-ordinate of point ');
y(i)=input('enter y co-ordinate of point ');
p(i,1)=[x(i)];
p(i,2)=[y(i)];
p(i,3)=[1];
end
p(n+1,1)=p(1,1);
p(n+1,2)=p(1,2);
d=input('angle to be rotated ');
rd=[cosd(d) sind(d) 0;-sind(d) cosd(d) 0;0 0 1];
t=[1 0 0;0 1 0;-a -b 1];
u=[1 0 0;0 1 0;a b 1];
q=p*t*rd*u
for j=1:n
r(j,1)=q(j,1);
r(j,2)=q(j,2);
end
r(n+1,1)=r(1,1);
r(n+1,2)=r(1,2);
plot(p(:,1),p(:,2))
hold on
plot(r(:,1),r(:,2))
OUTPUT:
enter no of points on the figure 3
enter x coordinate o point about which entity is to be rotated5
enter y coordinate o point about which entity is to be rotated5
enter x co-ordinate of point 1
enter y co-ordinate of point 2
enter x co-ordinate of point 3
enter y co-ordinate of point 3
enter x co-ordinate of point 9
enter y co-ordinate of point 11
angle to be rotated 270
Exercise 10. Write a generalized code to demonstrate that the 3D Rotation is not
commutative. Use a simple rectangular parallelepiped to prove the same by plotting the
results.
function ret = rotate3(data,theta,axis)
%ROTATE3 Rotate points[data] in 3D about X, Y orZ axis by 'theta'
radians in CCW dir.
% Input: set of points, theta[angle of rotation] and axis
abbr.['x','y' or 'z'] about
% which the pionts are to be rotated
if nargin~=3
error('Enter set of points, angle of roation, and the axis to
ratate about');
end
%creating matrix to work on
matrix = [data ones(size(data,1),1)];
%for easy use
ct = cos(theta);
st = sin(theta);
%deciding the matrix to use according to given parameter of axis
switch axis
case {'x','X'}
m_trans = [1 0 0 0; 0 ct -st 0; 0 st ct 0; 0 0 0 1];
case {'y', 'Y'}
m_trans = [ct 0 st 0; 0 1 0 0; -st 0 ct 0; 0 0 0 1];
case {'z', 'Z'}
m_trans = [ct -st 0 0; st ct 0 0; 0 0 1 0; 0 0 0 1];
otherwise
error('Choose axis from X Y or Z only!!')
end
%Calculating the multiplication and returning the data
ret = matrix*m_trans;
ret = ret(:,[1:3]);
end
Exercise 11: Design Problems
1. Develop a Matlab program with following details:
Design problem: Shaft
Input parameters: Power (KW), rpm of shaft, Allowable shear stress, factor of safety,
length of shaft
Output: diameter of shaft, weight of shaft.
CODE:
function FinalDimensions =
designShaft(power,rev_speed,tau,dia_ratio,length,rho)
%Calculating the torque first
power=power*1000;%kW to W
t = (60*power)/(2*pi*rev_speed);
t=t*1000;% Nm to Nmm
%From Strength criterion
FinalDimensions.OD = ((16*t)/(tau*pi*(1-dia_ratio^4)))^(1/3);%in mm
FinalDimensions.OD = ceil(FinalDimensions.OD); %rounding off
FinalDimensions.ID = floor(dia_ratio*FinalDimensions.OD);
FinalDimensions.wt = rho*pi*FinalDimensions.OD*FinalDimensions.OD*(1-
dia_ratio^2)*length;
FinalDimensions.wt = FinalDimensions.wt/10^9;%normalising to kg due to
OD taken in mm instead of m
struct2table(FinalDimensions);
end
2. Develop a Matlab program by assuming same data as in problem 1 to find the
material saving if hollow shaft is used instead of solid shaft
CODE:
function [ output_args ] = Excercise11Question2( input_args )
%UNTITLED9 Summary of this function goes here
% Detailed explanation goes here
clc;
clear all;
P = input('Power (kW): ');
N = input('Speed (rpm): ');
Smax = input('Allowable Shear Stress (MPa): ');
FOS = input('Factor of safety: ');
L = input('Length of shaft (m):');
D = input('Density of the shaft material (kg/m^3): ');
k = input('Ratio of outer to inner diameter: ');
T = 60000*P/(2*pi*N);
d = ((16*T*FOS/(pi*Smax*1000000))^(1/3))*1000
d2 = ((16*k*T*FOS/(pi*Smax*(k^4-1)*1000000))^(1/3))*1000
d1 = k*d2
Weight_hollow = pi*((d1/1000)^2 - (d2/1000)^2)*L*D/4
Weight_Solid = pi*(d/1000)^2*L*D/4
Percentage_Material_Saving = (Weight_Solid-
Weight_hollow)*100/Weight_Solid
display '%';
end
3. Develop a Matlab program to design a cotter joint with following details:
Input: Material properties, load applied on cotter joint (tension and compression), factor
of safety for different parts
Output: All dimensions of cotter joint
CODE:
function FinalDimensions = designCotter(P)
%P is in kN
clc;
load matlab.mat
fprintf('nChoose a Material')
ff=MaterialProperties1(:,1);
%Make a selectable list assigning the values of Syt
Syt = 400; %N/mm^2
fosR = 6; %for spigot, socket and Rod
fosC = 4; %for Cotter
%permissible stresses for Rod
RsigmaT = Syt/fosR;
RsigmaC = 2*Syt/fosR;
Rtau = Syt*0.5/fosR;
%permissible stresses for Cotter
CsigmaT = Syt/fosC;
CsigmaC = 2*Syt/fosC;
Ctau = Syt*0.5/fosC;
CsigmaB = CsigmaT;
%Calculation of Dimensions
d = ceil(sqrt(4*P*1000/(pi*RsigmaT)))+1; %Dia of rods
t = ceil(0.31*d); %thk. of cotter
% P = [pi/4 d2^2 - d2*t]sigmaT
d2 = ceil(max(roots([pi/4,-t,-P*1000/RsigmaT])))+1; %Dia of Spigot
d1 = ceil(max(roots([pi/4,-t,(-P*1000/RsigmaT)+(-
pi*0.25*d2^2)+(t*d2)])))+3;%Dia of Socket outside
d3 = ceil(1.5*d); d4 = ceil(2.4*d)+3;%Spigot Collar d3 and Socket
Collar d4
a = ceil(.75*d); c = a;
b = ceil(max((P*1000/(2*Ctau*t)),sqrt((((d4-
d2)/6)+(d2/4))*3*P*1000/t/CsigmaB)));%Width of cotter (Shear vs
Bending)
%Cotter Length ??!!
l= 2*d4;
%Verification for crushing and shearing in spigot
flag=1;
if RsigmaC <= (P*1000/t/d2)
fprintf('nSpigot Failing under CRUSHING!')
flag = 0;
end
if Rtau <= (P*1000/2/a/d2)
fprintf('nSpigot Failing under SHEARING!')
flag = 0;
end
%Verification for crushing and shearing in socket
if RsigmaC <= (P*1000/t/(d4-d2))
fprintf('nSocket Failing under CRUSHING!')
flag = 0;
end
if Rtau <= (P*1000/2/c/(d4-d2))
fprintf('nSocket Failing under SHEARING!')
flag = 0;
end
%Spigot collar thk.
t1 = ceil(.45*d);
if flag == 1
FinalDimensions.Parameter = {'Force Acting'; 'Diameter of Each
Rod'; 'Outside Diameter of Socket'; 'Diameter of Spigot or inside
diameter of Socket'; 'Diameter of Spigot-collar'; 'Diameter of Socket-
collar'; 'Distance from end of slot to the end of Spigot on Rod-B';
'Mean width of Cotter'; 'Axial distance from slot to end of Socket-
collar'; 'Thickness of Cotter'; 'Thickness of Spigot-collar'; 'Length
of Cotter'};
FinalDimensions.Value = [P; d; d1; d2; d3; d4; a; b; c; t; t1;
l];
FinalDimensions.Unit = {'(kN)'; '(mm)'; '(mm)'; '(mm)';
'(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'};
FinalDimensions = struct2table(FinalDimensions);
end
fprintf('n')
4. Develop a Matlab code for the following data:
Objective: Selection of single row deep groove ball bearing
Input data: Radial load, axial load, expected life in hours, diameter of shaft
Output: Bearing designation
CODE:
clc;
clear all;
d=input('Enter the inner diameter of the shaft:');
Fr=input('Enter the radial load on bearing (kN):');
Fa=input('Enter the axial load on bearing (kN):');
Lh=input('Enter the expected life (hours):');
n=input('Enter the RPM:');
%the load factors assumed to be 1 each for both Fr and Fa
k=3;
P=Fr+Fa;
L=60*n*Lh;
co=(P*(L/(10^6))^(1/k));
switch d
case 25
if (co<4.36)
disp('The Bearing code is: 61805')
elseif (co>=4.36)&&(co<7.02)
disp('The Bearing code is: 61905')
elseif (co>=7.02)&&(co<8.06)
disp('The Bearing code is: 16005')
elseif (co>=8.06)&&(co<10.6)
disp('The Bearing code is: 68205')
elseif (co>=10.6)&&(co<11.9)
disp('The Bearing code is: 6005')
elseif (co>=11.9)&&(co<14.8)
disp('The Bearing code is: 6205')
elseif (co>=14.8)&&(co<17.8)
disp('The Bearing code is: 6205 ETN9')
elseif (co>=17.8)&&(co<23.4)
disp('The Bearing code is: 6305')
elseif (co>=23.4)&&(co<26)
disp('The Bearing code is: 6305 ETN9')
elseif (co>=26)&&(co<35.8)
disp('The Bearing code is: 6405')
else
disp('No bearings available for the given load and diameter')
end
case 28
if (co<16.8)
disp('The Bearing code is: 62/28')
elseif (co>=16.8)&&(co<25.1)
disp('The Bearing code is: 63/28')
else
disp('No Bearings available for the given load and
diameter.')
end
case 30
if (co<4.49)
disp('The Bearing code is: 61806')
elseif (co>=4.49)&&(co<7.28)
disp('The Bearing code is: 61906')
elseif (co>=7.28)&&(co<11.9)
disp('The Bearing code is: 16006')
elseif (co>=11.9)&&(co<13.8)
disp('The Bearing code is: 6006')
elseif (co>=13.8)&&(co<15.9)
disp('The Bearing code is: 98206')
elseif (co>=15.9)&&(co<20.3)
disp('The Bearing code is: 6206')
elseif (co>=20.3)&&(co<23.4)
disp('The Bearing code is: 6206 ETN9')
elseif (co>=23.4)&&(co<29.6)
disp('The Bearing code is: 6306 ')
elseif (co>=29.6)&&(co<32.5)
disp('The Bearing code is: 6306 ETN9')
elseif (co>=32.5)&&(co<43.6)
disp('The Bearing code is: 6406')
else
disp('There are no bearings available for the given load
carrying capacity and diameter.')
end
case 35
if (co<4.75)
disp('The Bearing code is: 61807')
elseif (co>=4.75)&&(co<9.56)
disp('The Bearing code is: 61907')
elseif (co>=9.56)&&(co<13)
disp('The Bearing code is: 16007')
elseif (co>=13)&&(co<16.8)
disp('The Bearing code is: 6007')
elseif (co>=16.8)&&(co<27)
disp('The Bearing code is: 6207')
elseif (co>=27)&&(co<31.2)
disp('The Bearing code is: 6207 ETN9')
elseif (co>=31.2)&&(co<35.1)
disp('The Bearing code is: 6307')
elseif (co>=35.1)&&(co<55.3)
disp('The Bearing code is: 6407')
else
disp('There are no bearings available for the given load
carrying capacity and diameter.')
end
otherwise
disp('Please enter a diameter from the above given options.')
end

Mais conteúdo relacionado

Mais procurados

Finite element using ansys
Finite element using ansysFinite element using ansys
Finite element using ansysjivanpawar5
 
Can Crusher Device - Theory of Machines Mini-Project
Can Crusher Device - Theory of Machines Mini-ProjectCan Crusher Device - Theory of Machines Mini-Project
Can Crusher Device - Theory of Machines Mini-ProjectEsraa Fathy
 
Magnestic abrasive finishing process
Magnestic abrasive finishing processMagnestic abrasive finishing process
Magnestic abrasive finishing processrahul lokhande
 
Abrasive jet machining
Abrasive jet machiningAbrasive jet machining
Abrasive jet machiningmohit99033
 
Additive manufacturing
Additive  manufacturingAdditive  manufacturing
Additive manufacturingvirat virat
 
COMPUTER AIDED MACHINE DRAWING LAB MANUAL
COMPUTER AIDED MACHINE DRAWING LAB MANUALCOMPUTER AIDED MACHINE DRAWING LAB MANUAL
COMPUTER AIDED MACHINE DRAWING LAB MANUALASHOK KUMAR RAJENDRAN
 
Abrasive water jet machining
Abrasive water jet machiningAbrasive water jet machining
Abrasive water jet machiningmohit99033
 
Application of Additive Manufacturing in Aerospace Industry
Application of Additive Manufacturing in Aerospace IndustryApplication of Additive Manufacturing in Aerospace Industry
Application of Additive Manufacturing in Aerospace IndustryAbhijeet Agarwal
 
Workholding devices
Workholding devicesWorkholding devices
Workholding devicesad_svh
 
Various types of surfaces 131044119001
Various types of surfaces 131044119001Various types of surfaces 131044119001
Various types of surfaces 131044119001rockrakos
 
Laser Beam Machining
Laser Beam MachiningLaser Beam Machining
Laser Beam MachiningSahil Dev
 
Finite Element Analysis - UNIT-4
Finite Element Analysis - UNIT-4Finite Element Analysis - UNIT-4
Finite Element Analysis - UNIT-4propaul
 
Electrochemical Machining
Electrochemical MachiningElectrochemical Machining
Electrochemical MachiningAVINASH JURIANI
 
Fatigue Analysis of Structures (Aerospace Application)
Fatigue Analysis of Structures (Aerospace Application)Fatigue Analysis of Structures (Aerospace Application)
Fatigue Analysis of Structures (Aerospace Application)Mahdi Damghani
 
Tool changing mechanism in cnc machine
Tool changing mechanism in cnc machineTool changing mechanism in cnc machine
Tool changing mechanism in cnc machineBhaveshChaudhari21
 

Mais procurados (20)

Finite element using ansys
Finite element using ansysFinite element using ansys
Finite element using ansys
 
Dynamics of Machinery Unit IV
Dynamics of Machinery Unit IVDynamics of Machinery Unit IV
Dynamics of Machinery Unit IV
 
Introduction to robotics
Introduction to roboticsIntroduction to robotics
Introduction to robotics
 
Can Crusher Device - Theory of Machines Mini-Project
Can Crusher Device - Theory of Machines Mini-ProjectCan Crusher Device - Theory of Machines Mini-Project
Can Crusher Device - Theory of Machines Mini-Project
 
Magnestic abrasive finishing process
Magnestic abrasive finishing processMagnestic abrasive finishing process
Magnestic abrasive finishing process
 
Abrasive jet machining
Abrasive jet machiningAbrasive jet machining
Abrasive jet machining
 
Additive manufacturing
Additive  manufacturingAdditive  manufacturing
Additive manufacturing
 
COMPUTER AIDED MACHINE DRAWING LAB MANUAL
COMPUTER AIDED MACHINE DRAWING LAB MANUALCOMPUTER AIDED MACHINE DRAWING LAB MANUAL
COMPUTER AIDED MACHINE DRAWING LAB MANUAL
 
Abrasive water jet machining
Abrasive water jet machiningAbrasive water jet machining
Abrasive water jet machining
 
Application of Additive Manufacturing in Aerospace Industry
Application of Additive Manufacturing in Aerospace IndustryApplication of Additive Manufacturing in Aerospace Industry
Application of Additive Manufacturing in Aerospace Industry
 
Workholding devices
Workholding devicesWorkholding devices
Workholding devices
 
PROCESS PLANNING AND COST ESTIMATION
PROCESS PLANNING AND COST ESTIMATIONPROCESS PLANNING AND COST ESTIMATION
PROCESS PLANNING AND COST ESTIMATION
 
Various types of surfaces 131044119001
Various types of surfaces 131044119001Various types of surfaces 131044119001
Various types of surfaces 131044119001
 
Laser Beam Machining
Laser Beam MachiningLaser Beam Machining
Laser Beam Machining
 
Additive manufacturing ppt
Additive manufacturing pptAdditive manufacturing ppt
Additive manufacturing ppt
 
Finite Element Analysis - UNIT-4
Finite Element Analysis - UNIT-4Finite Element Analysis - UNIT-4
Finite Element Analysis - UNIT-4
 
Electrochemical Machining
Electrochemical MachiningElectrochemical Machining
Electrochemical Machining
 
Fatigue Analysis of Structures (Aerospace Application)
Fatigue Analysis of Structures (Aerospace Application)Fatigue Analysis of Structures (Aerospace Application)
Fatigue Analysis of Structures (Aerospace Application)
 
Non conventional machining process
Non conventional machining processNon conventional machining process
Non conventional machining process
 
Tool changing mechanism in cnc machine
Tool changing mechanism in cnc machineTool changing mechanism in cnc machine
Tool changing mechanism in cnc machine
 

Semelhante a Matlab assignment

Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search TechniquesShakil Ahmed
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++rpiitcbme
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing DesignV Tripathi
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingSaurabh Singh
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsSunil Yadav
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestorShakil Ahmed
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
The Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorThe Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorAbhranil Das
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Introduction to CFD FORTRAN code
Introduction to CFD FORTRAN codeIntroduction to CFD FORTRAN code
Introduction to CFD FORTRAN codeBehnam Bozorgmehr
 
PYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdfPYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdfNeeraj381934
 
Basic python programs
Basic python programsBasic python programs
Basic python programsRaginiJain21
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 

Semelhante a Matlab assignment (20)

Cs580
Cs580Cs580
Cs580
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm ProblemsLeet Code May Coding Challenge - DataStructure and Algorithm Problems
Leet Code May Coding Challenge - DataStructure and Algorithm Problems
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
The Moore-Spiegel Oscillator
The Moore-Spiegel OscillatorThe Moore-Spiegel Oscillator
The Moore-Spiegel Oscillator
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Matlab file
Matlab file Matlab file
Matlab file
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Introduction to CFD FORTRAN code
Introduction to CFD FORTRAN codeIntroduction to CFD FORTRAN code
Introduction to CFD FORTRAN code
 
PYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdfPYTHON_PROGRAM(1-34).pdf
PYTHON_PROGRAM(1-34).pdf
 
week-17x
week-17xweek-17x
week-17x
 
week-18x
week-18xweek-18x
week-18x
 
Basic python programs
Basic python programsBasic python programs
Basic python programs
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 

Mais de Rutvik

Refrigeration and air conditioning-5
Refrigeration and air conditioning-5Refrigeration and air conditioning-5
Refrigeration and air conditioning-5Rutvik
 
Refrigeration and air conditioning-4
Refrigeration and air conditioning-4Refrigeration and air conditioning-4
Refrigeration and air conditioning-4Rutvik
 
Refrigeration and air conditioning-3
Refrigeration and air conditioning-3Refrigeration and air conditioning-3
Refrigeration and air conditioning-3Rutvik
 
Refrigeration and air conditioning-2
Refrigeration and air conditioning-2Refrigeration and air conditioning-2
Refrigeration and air conditioning-2Rutvik
 
Transmission system numerical
Transmission system numericalTransmission system numerical
Transmission system numericalRutvik
 
Resistance spot welding
Resistance spot weldingResistance spot welding
Resistance spot weldingRutvik
 
Gears- Design
Gears- DesignGears- Design
Gears- DesignRutvik
 
Ultrasonic welding questions
Ultrasonic welding questionsUltrasonic welding questions
Ultrasonic welding questionsRutvik
 
Microwave processing questions
Microwave processing questionsMicrowave processing questions
Microwave processing questionsRutvik
 
E beam welding questions
E beam welding questionsE beam welding questions
E beam welding questionsRutvik
 
Concentrated solar power
Concentrated solar powerConcentrated solar power
Concentrated solar powerRutvik
 
Pressure vessel questions
Pressure vessel questionsPressure vessel questions
Pressure vessel questionsRutvik
 
2004 Tsunami
2004 Tsunami2004 Tsunami
2004 TsunamiRutvik
 

Mais de Rutvik (13)

Refrigeration and air conditioning-5
Refrigeration and air conditioning-5Refrigeration and air conditioning-5
Refrigeration and air conditioning-5
 
Refrigeration and air conditioning-4
Refrigeration and air conditioning-4Refrigeration and air conditioning-4
Refrigeration and air conditioning-4
 
Refrigeration and air conditioning-3
Refrigeration and air conditioning-3Refrigeration and air conditioning-3
Refrigeration and air conditioning-3
 
Refrigeration and air conditioning-2
Refrigeration and air conditioning-2Refrigeration and air conditioning-2
Refrigeration and air conditioning-2
 
Transmission system numerical
Transmission system numericalTransmission system numerical
Transmission system numerical
 
Resistance spot welding
Resistance spot weldingResistance spot welding
Resistance spot welding
 
Gears- Design
Gears- DesignGears- Design
Gears- Design
 
Ultrasonic welding questions
Ultrasonic welding questionsUltrasonic welding questions
Ultrasonic welding questions
 
Microwave processing questions
Microwave processing questionsMicrowave processing questions
Microwave processing questions
 
E beam welding questions
E beam welding questionsE beam welding questions
E beam welding questions
 
Concentrated solar power
Concentrated solar powerConcentrated solar power
Concentrated solar power
 
Pressure vessel questions
Pressure vessel questionsPressure vessel questions
Pressure vessel questions
 
2004 Tsunami
2004 Tsunami2004 Tsunami
2004 Tsunami
 

Último

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayEpec Engineered Technologies
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 

Último (20)

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 

Matlab assignment

  • 1.
  • 2. Exercise 5: Write a generalized code to generate a line between the given two end points using DDA line algorithm (accommodate all the four + four conditions as discussed in the theory class). CODE: clc; clear all; X_0 = input('X_0: '); Y_0 = input ('Y_0: '); X_1 = input('X_1: '); Y_1 = input('Y_1: '); dX = abs(X_0 - X_1); dY = abs(Y_0 - Y_1); sx = sign(X_1-X_0); sy = sign(Y_1-Y_0); n = max(dY,dX); X(1) = X_0; Y(1) = Y_0; j=1; for i=0:1:n if (X_1==X)&(Y_1==Y) break end j=j+1; X(j) = X(j-1)+(dX/n)*sx; Y(j) = Y(j-1)+(dY/n)*sy; end plot(round(X),round(Y)); OUTPUT: X_0: -3 Y_0: 5 X_1: 6 Y_1: -8
  • 3. Exercise 6: Write a generalized code to generate a line between the given two end points using Bresenhams’ algorithm. CODE: clc; clear all; enter='X1: ' x1=input(enter); enter='Y1: ' y1=input(enter); enter='X2: ' x2=input(enter); enter='Y2: ' y2=input(enter); dx=abs(x2-x1); dy=abs(y2-y1); p=(2*dy)-dx; i=1; if(x1>x2) x=x2; y=y2; xEnd=x1; temp=x2; else x=x1; y=y1; xEnd=x2; temp=x1; end a=zeros(abs(xEnd-temp),1); b=zeros(abs(xEnd-temp),1); a(1,1)=(x); b(1,1)=(y); while x<xEnd x=x+1; i=i+1; a(i,1)=round(x); if p<0 p=p+2*dy; b(i,1)=round(y); else if((y2-y1)/(x2-x1))>0 y=y+1; else y=y-1; end p=p+(2*(dy-dx)); b(i,1)=y; end plot(a,b) end
  • 4. OUTPUT: X1: 2 Y1: 6 X2: 9 Y2: 11 Exercise 7: Write a generalized code to generate a circle for a user specified radius and coordinates of center point. CODE: clc; clear all; close all; x1=input('x_centre: '); y1=input('y_centre: '); R=input('Radius: '); x=0; y=R; p=1-R; m=[x,y]; while(x<y) x=x+1 if(p<0) p=p+2*x+1 else y=y-1 p=p+2*(x-y)+1 end m=[m;x y] end m; x=m(:,1); y=m(:,2); x2=x1+x; y2=y1+y; x3=x1-x; y3=y1+y;
  • 5. x4=x1+x; y4=y1-y; x5=x1-x; y5=y1-y; x6=x1+y; y6=y1+x; x7=x1-y; y7=y1+x; x8=x1+y; y8=y1-x; x9=x1-y; y9=y1-x; plot(x2,y2) hold on plot(x3,y3) hold on plot(x4,y4) hold on plot(x5,y5) hold on plot(x6,y6) hold on plot(x7,y7) hold on plot(x8,y8) hold on plot(x9,y9) OUTPUT: x_centre: 5 y_centre: 3 Radius: 8 x = 1 p = -4 m = 0 8 1 8 x = 2 p = 1 m = 0 8 1 8
  • 6. 2 8 x = 3 y = 7 p = -6 m = 0 8 1 8 2 8 3 7 x = 4 p = 3 m = 0 8 1 8 2 8 3 7 4 7 x = 5 y = 6 p = 2 m = 0 8 1 8 2 8 3 7 4 7 5 6 x = 6 y = 5 p = 5
  • 7. m = 0 8 1 8 2 8 3 7 4 7 5 6 6 5 Exercise 8. Write a generalized code to perform a 2D translation on user specified points (For line, triangle, and quadrilateral). Plot the figures before and after transformation. CODE: clear all; close all; n= input('enter number of points of the figure= '); tx= input('insert the value of translation in x direction= '); ty= input('insert the value of translation in y direction= '); for i=1:n x(i)= input('insert initial x co-ordinate of point= '); y(i)= input('insert initial y co-ordinate of point= '); P(i,1)= [x(i)]; P(i,2)= [y(i)]; P(i,3)= [1]; end P(n+1,1)=P(1,1); P(n+1,2)=P(1,2); P(n+1,3)= [1]; A= [1 0 0; 0 1 0;tx ty 1]; B= P*A; B(n+1,1)=B(1,1); B(n+1,2)=B(1,2); B(n+1,3)= [1]; plot(P(:,1),P(:,2)); hold on; plot(B(:,1),B(:,2));
  • 8. OUTPUT: enter number of points of the figure= 4 insert the value of translation in x direction= 5 insert the value of translation in y direction= 6 insert initial x co-ordinate of point= 2 insert initial y co-ordinate of point= 2 insert initial x co-ordinate of point= 4 insert initial y co-ordinate of point= 3 insert initial x co-ordinate of point= 8 insert initial y co-ordinate of point= 9 insert initial x co-ordinate of point= 7 insert initial y co-ordinate of point= -3 8a. Demonstrate Scaling, Reflection and Rotation about the coordinate axes. clc; clear all; close all; w= input('Select type of transformation(1=scaling,2=reflection about xaxis,3=reflection about y-axis,4=rotation)=') switch w case 1
  • 9. n= input('enter number of points of the figure= '); ax= input('insert the value of scaling in x direction= '); dy= input('insert the value of scaling in y direction= '); for i=1:n x(i)= input('insert initial x co-ordinate of point= '); y(i)= input('insert initial y co-ordinate of point= '); P(i,1)= [x(i)]; P(i,2)= [y(i)]; P(i,3)= [1]; end P(n+1,1)=P(1,1); P(n+1,2)=P(1,2); P(n+1,3)= [1]; A= [ax 0 0; 0 dy 0;0 0 1]; B= P*A; B(n+1,1)=B(1,1); B(n+1,2)=B(1,2); B(n+1,3)= [1]; plot(P(:,1),P(:,2)); hold on; plot(B(:,1),B(:,2)); case 2 n= input('enter number of points of the figure= '); for i=1:n x(i)= input('insert initial x co-ordinate of point= '); y(i)= input('insert initial y co-ordinate of point= '); P(i,1)= [x(i)]; P(i,2)= [y(i)]; P(i,3)= [1]; end P(n+1,1)=P(1,1); P(n+1,2)=P(1,2); P(n+1,3)= [1]; A= [1 0 0; 0 -1 0;0 0 1]; B= P*A; B(n+1,1)=B(1,1); B(n+1,2)=B(1,2); B(n+1,3)= [1]; plot(P(:,1),P(:,2)); hold on; plot(B(:,1),B(:,2)); case 3 n= input('enter number of points of the figure= '); for i=1:n x(i)= input('insert initial x co-ordinate of point= '); y(i)= input('insert initial y co-ordinate of point= '); P(i,1)= [x(i)]; P(i,2)= [y(i)]; P(i,3)= [1]; end P(n+1,1)=P(1,1); P(n+1,2)=P(1,2);
  • 10. P(n+1,3)= [1]; A= [-1 0 0; 0 1 0;0 0 1]; B= P*A; B(n+1,1)=B(1,1); B(n+1,2)=B(1,2); B(n+1,3)= [1]; plot(P(:,1),P(:,2)); hold on; plot(B(:,1),B(:,2)); case 4 n= input('enter number of points of the figure= '); o= input('enter the angle of rotation= ') for i=1:n x(i)= input('insert initial x co-ordinate of point= '); y(i)= input('insert initial y co-ordinate of point= '); P(i,1)= [x(i)]; P(i,2)= [y(i)]; P(i,3)= [1]; end P(n+1,1)=P(1,1); P(n+1,2)=P(1,2); P(n+1,3)= [1]; A= [1 0 0; 0 1 0;tx ty 1]; B= P*A; B(n+1,1)=B(1,1); B(n+1,2)=B(1,2); B(n+1,3)= [1]; plot(P(:,1),P(:,2)); hold on; plot(B(:,1),B(:,2)); end OUTPUT: Select type of transformation(1=scaling,2=reflection about xaxis,3=reflection about y-axis,4=rotation)=1 enter number of points of the figure= 4 insert the value of scaling in x direction= 3 insert the value of scaling in y direction= 2 insert initial x co-ordinate of point= 2 insert initial y co-ordinate of point= 2 insert initial x co-ordinate of point= -3 insert initial y co-ordinate of point= 6 insert initial x co-ordinate of point= 5 insert initial y co-ordinate of point= 6
  • 11. insert initial x co-ordinate of point= 9 insert initial y co-ordinate of point= 11 Exercise 9: Write a generalized code to perform a 2D Rotation about an user specified point on user specified entities (For line, triangle, and quadrilateral). Plot the figures before and after transformation. CODE: clc; clear all; close all; n=input('enter no of points on the figure '); a=input('enter x coordinate o point about which entity is to be rotated'); b=input('enter y coordinate o point about which entity is to be rotated'); p=zeros(n,3); for i=1:n x(i)=input('enter x co-ordinate of point '); y(i)=input('enter y co-ordinate of point '); p(i,1)=[x(i)]; p(i,2)=[y(i)]; p(i,3)=[1]; end p(n+1,1)=p(1,1); p(n+1,2)=p(1,2); d=input('angle to be rotated '); rd=[cosd(d) sind(d) 0;-sind(d) cosd(d) 0;0 0 1]; t=[1 0 0;0 1 0;-a -b 1]; u=[1 0 0;0 1 0;a b 1]; q=p*t*rd*u for j=1:n r(j,1)=q(j,1); r(j,2)=q(j,2); end r(n+1,1)=r(1,1); r(n+1,2)=r(1,2); plot(p(:,1),p(:,2)) hold on plot(r(:,1),r(:,2)) OUTPUT: enter no of points on the figure 3 enter x coordinate o point about which entity is to be rotated5 enter y coordinate o point about which entity is to be rotated5 enter x co-ordinate of point 1
  • 12. enter y co-ordinate of point 2 enter x co-ordinate of point 3 enter y co-ordinate of point 3 enter x co-ordinate of point 9 enter y co-ordinate of point 11 angle to be rotated 270 Exercise 10. Write a generalized code to demonstrate that the 3D Rotation is not commutative. Use a simple rectangular parallelepiped to prove the same by plotting the results. function ret = rotate3(data,theta,axis) %ROTATE3 Rotate points[data] in 3D about X, Y orZ axis by 'theta' radians in CCW dir. % Input: set of points, theta[angle of rotation] and axis abbr.['x','y' or 'z'] about % which the pionts are to be rotated if nargin~=3 error('Enter set of points, angle of roation, and the axis to ratate about'); end
  • 13. %creating matrix to work on matrix = [data ones(size(data,1),1)]; %for easy use ct = cos(theta); st = sin(theta); %deciding the matrix to use according to given parameter of axis switch axis case {'x','X'} m_trans = [1 0 0 0; 0 ct -st 0; 0 st ct 0; 0 0 0 1]; case {'y', 'Y'} m_trans = [ct 0 st 0; 0 1 0 0; -st 0 ct 0; 0 0 0 1]; case {'z', 'Z'} m_trans = [ct -st 0 0; st ct 0 0; 0 0 1 0; 0 0 0 1]; otherwise error('Choose axis from X Y or Z only!!') end %Calculating the multiplication and returning the data ret = matrix*m_trans; ret = ret(:,[1:3]); end Exercise 11: Design Problems 1. Develop a Matlab program with following details: Design problem: Shaft Input parameters: Power (KW), rpm of shaft, Allowable shear stress, factor of safety, length of shaft Output: diameter of shaft, weight of shaft. CODE: function FinalDimensions = designShaft(power,rev_speed,tau,dia_ratio,length,rho) %Calculating the torque first power=power*1000;%kW to W t = (60*power)/(2*pi*rev_speed); t=t*1000;% Nm to Nmm %From Strength criterion FinalDimensions.OD = ((16*t)/(tau*pi*(1-dia_ratio^4)))^(1/3);%in mm FinalDimensions.OD = ceil(FinalDimensions.OD); %rounding off FinalDimensions.ID = floor(dia_ratio*FinalDimensions.OD); FinalDimensions.wt = rho*pi*FinalDimensions.OD*FinalDimensions.OD*(1- dia_ratio^2)*length; FinalDimensions.wt = FinalDimensions.wt/10^9;%normalising to kg due to OD taken in mm instead of m
  • 14. struct2table(FinalDimensions); end 2. Develop a Matlab program by assuming same data as in problem 1 to find the material saving if hollow shaft is used instead of solid shaft CODE: function [ output_args ] = Excercise11Question2( input_args ) %UNTITLED9 Summary of this function goes here % Detailed explanation goes here clc; clear all; P = input('Power (kW): '); N = input('Speed (rpm): '); Smax = input('Allowable Shear Stress (MPa): '); FOS = input('Factor of safety: '); L = input('Length of shaft (m):'); D = input('Density of the shaft material (kg/m^3): '); k = input('Ratio of outer to inner diameter: '); T = 60000*P/(2*pi*N); d = ((16*T*FOS/(pi*Smax*1000000))^(1/3))*1000 d2 = ((16*k*T*FOS/(pi*Smax*(k^4-1)*1000000))^(1/3))*1000 d1 = k*d2 Weight_hollow = pi*((d1/1000)^2 - (d2/1000)^2)*L*D/4 Weight_Solid = pi*(d/1000)^2*L*D/4 Percentage_Material_Saving = (Weight_Solid- Weight_hollow)*100/Weight_Solid display '%'; end 3. Develop a Matlab program to design a cotter joint with following details: Input: Material properties, load applied on cotter joint (tension and compression), factor of safety for different parts Output: All dimensions of cotter joint CODE: function FinalDimensions = designCotter(P) %P is in kN clc; load matlab.mat fprintf('nChoose a Material') ff=MaterialProperties1(:,1); %Make a selectable list assigning the values of Syt Syt = 400; %N/mm^2 fosR = 6; %for spigot, socket and Rod fosC = 4; %for Cotter %permissible stresses for Rod RsigmaT = Syt/fosR; RsigmaC = 2*Syt/fosR;
  • 15. Rtau = Syt*0.5/fosR; %permissible stresses for Cotter CsigmaT = Syt/fosC; CsigmaC = 2*Syt/fosC; Ctau = Syt*0.5/fosC; CsigmaB = CsigmaT; %Calculation of Dimensions d = ceil(sqrt(4*P*1000/(pi*RsigmaT)))+1; %Dia of rods t = ceil(0.31*d); %thk. of cotter % P = [pi/4 d2^2 - d2*t]sigmaT d2 = ceil(max(roots([pi/4,-t,-P*1000/RsigmaT])))+1; %Dia of Spigot d1 = ceil(max(roots([pi/4,-t,(-P*1000/RsigmaT)+(- pi*0.25*d2^2)+(t*d2)])))+3;%Dia of Socket outside d3 = ceil(1.5*d); d4 = ceil(2.4*d)+3;%Spigot Collar d3 and Socket Collar d4 a = ceil(.75*d); c = a; b = ceil(max((P*1000/(2*Ctau*t)),sqrt((((d4- d2)/6)+(d2/4))*3*P*1000/t/CsigmaB)));%Width of cotter (Shear vs Bending) %Cotter Length ??!! l= 2*d4; %Verification for crushing and shearing in spigot flag=1; if RsigmaC <= (P*1000/t/d2) fprintf('nSpigot Failing under CRUSHING!') flag = 0; end if Rtau <= (P*1000/2/a/d2) fprintf('nSpigot Failing under SHEARING!') flag = 0; end %Verification for crushing and shearing in socket if RsigmaC <= (P*1000/t/(d4-d2)) fprintf('nSocket Failing under CRUSHING!') flag = 0; end if Rtau <= (P*1000/2/c/(d4-d2)) fprintf('nSocket Failing under SHEARING!') flag = 0; end %Spigot collar thk. t1 = ceil(.45*d);
  • 16. if flag == 1 FinalDimensions.Parameter = {'Force Acting'; 'Diameter of Each Rod'; 'Outside Diameter of Socket'; 'Diameter of Spigot or inside diameter of Socket'; 'Diameter of Spigot-collar'; 'Diameter of Socket- collar'; 'Distance from end of slot to the end of Spigot on Rod-B'; 'Mean width of Cotter'; 'Axial distance from slot to end of Socket- collar'; 'Thickness of Cotter'; 'Thickness of Spigot-collar'; 'Length of Cotter'}; FinalDimensions.Value = [P; d; d1; d2; d3; d4; a; b; c; t; t1; l]; FinalDimensions.Unit = {'(kN)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'; '(mm)'}; FinalDimensions = struct2table(FinalDimensions); end fprintf('n') 4. Develop a Matlab code for the following data: Objective: Selection of single row deep groove ball bearing Input data: Radial load, axial load, expected life in hours, diameter of shaft Output: Bearing designation CODE: clc; clear all; d=input('Enter the inner diameter of the shaft:'); Fr=input('Enter the radial load on bearing (kN):'); Fa=input('Enter the axial load on bearing (kN):'); Lh=input('Enter the expected life (hours):'); n=input('Enter the RPM:'); %the load factors assumed to be 1 each for both Fr and Fa k=3; P=Fr+Fa; L=60*n*Lh; co=(P*(L/(10^6))^(1/k)); switch d case 25 if (co<4.36) disp('The Bearing code is: 61805') elseif (co>=4.36)&&(co<7.02) disp('The Bearing code is: 61905') elseif (co>=7.02)&&(co<8.06) disp('The Bearing code is: 16005') elseif (co>=8.06)&&(co<10.6) disp('The Bearing code is: 68205') elseif (co>=10.6)&&(co<11.9) disp('The Bearing code is: 6005') elseif (co>=11.9)&&(co<14.8) disp('The Bearing code is: 6205') elseif (co>=14.8)&&(co<17.8) disp('The Bearing code is: 6205 ETN9')
  • 17. elseif (co>=17.8)&&(co<23.4) disp('The Bearing code is: 6305') elseif (co>=23.4)&&(co<26) disp('The Bearing code is: 6305 ETN9') elseif (co>=26)&&(co<35.8) disp('The Bearing code is: 6405') else disp('No bearings available for the given load and diameter') end case 28 if (co<16.8) disp('The Bearing code is: 62/28') elseif (co>=16.8)&&(co<25.1) disp('The Bearing code is: 63/28') else disp('No Bearings available for the given load and diameter.') end case 30 if (co<4.49) disp('The Bearing code is: 61806') elseif (co>=4.49)&&(co<7.28) disp('The Bearing code is: 61906') elseif (co>=7.28)&&(co<11.9) disp('The Bearing code is: 16006') elseif (co>=11.9)&&(co<13.8) disp('The Bearing code is: 6006') elseif (co>=13.8)&&(co<15.9) disp('The Bearing code is: 98206') elseif (co>=15.9)&&(co<20.3) disp('The Bearing code is: 6206') elseif (co>=20.3)&&(co<23.4) disp('The Bearing code is: 6206 ETN9') elseif (co>=23.4)&&(co<29.6) disp('The Bearing code is: 6306 ') elseif (co>=29.6)&&(co<32.5) disp('The Bearing code is: 6306 ETN9') elseif (co>=32.5)&&(co<43.6) disp('The Bearing code is: 6406') else disp('There are no bearings available for the given load carrying capacity and diameter.') end case 35 if (co<4.75) disp('The Bearing code is: 61807') elseif (co>=4.75)&&(co<9.56) disp('The Bearing code is: 61907') elseif (co>=9.56)&&(co<13) disp('The Bearing code is: 16007') elseif (co>=13)&&(co<16.8) disp('The Bearing code is: 6007')
  • 18. elseif (co>=16.8)&&(co<27) disp('The Bearing code is: 6207') elseif (co>=27)&&(co<31.2) disp('The Bearing code is: 6207 ETN9') elseif (co>=31.2)&&(co<35.1) disp('The Bearing code is: 6307') elseif (co>=35.1)&&(co<55.3) disp('The Bearing code is: 6407') else disp('There are no bearings available for the given load carrying capacity and diameter.') end otherwise disp('Please enter a diameter from the above given options.') end