SlideShare a Scribd company logo
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

More Related Content

What's hot

Fracture mechanics
Fracture mechanicsFracture mechanics
Fracture mechanics
Deepak Samal
 
Casting
CastingCasting
Casting
Manoj Yadav
 
Abrasive jet machining
Abrasive jet machiningAbrasive jet machining
Abrasive jet machining
Arjun Patial
 
Ultrasonic Machining by Ms Shikha Kashyap
Ultrasonic Machining by Ms Shikha KashyapUltrasonic Machining by Ms Shikha Kashyap
Ultrasonic Machining by Ms Shikha Kashyap
THE NORTHCAP UNIVERSITY
 
Theory of Metal Cutting
Theory of Metal CuttingTheory of Metal Cutting
Theory of Metal Cutting
Kunduru Srinivasulu Reddy
 
PERFORMANCE AND ANALYSIS OF MILLING TOOLS DYNAMOMETER
	PERFORMANCE AND ANALYSIS OF MILLING TOOLS DYNAMOMETER	PERFORMANCE AND ANALYSIS OF MILLING TOOLS DYNAMOMETER
PERFORMANCE AND ANALYSIS OF MILLING TOOLS DYNAMOMETER
sathish sak
 
Hermite cubic spline curve
Hermite cubic spline curveHermite cubic spline curve
Hermite cubic spline curve
Deepak Antil
 
Camtools presentation 14 15
Camtools presentation 14 15Camtools presentation 14 15
Camtools presentation 14 15
CAM TOOLS
 
Cnc program writing
Cnc program writingCnc program writing
Cnc program writing
mazharmustafa3
 
Finite Element Analysis - UNIT-1
Finite Element Analysis - UNIT-1Finite Element Analysis - UNIT-1
Finite Element Analysis - UNIT-1
propaul
 
two degree of freddom system
two degree of freddom systemtwo degree of freddom system
two degree of freddom system
Yash Patel
 
Me8097 non destructive testing and evaluation
Me8097 non destructive testing and evaluationMe8097 non destructive testing and evaluation
Me8097 non destructive testing and evaluation
sivasan4
 
Electron beam micromachining
Electron beam micromachiningElectron beam micromachining
Electron beam micromachining
Anurag Chaudhary
 
ED7104 VAC_notes
ED7104 VAC_notesED7104 VAC_notes
Magnestic abrasive finishing process
Magnestic abrasive finishing processMagnestic abrasive finishing process
Magnestic abrasive finishing process
rahul lokhande
 
Advanced machining processes
Advanced machining processesAdvanced machining processes
Advanced machining processes
Gopinath Guru
 
Sheet metal process unit 4 notes
Sheet metal process unit 4 notesSheet metal process unit 4 notes
Sheet metal process unit 4 notes
rmkcet
 
Fundamentals of metal forming processes
Fundamentals of metal forming processesFundamentals of metal forming processes
Fundamentals of metal forming processes
Naman Dave
 
GD and T Basic tutuorial
GD and T Basic tutuorialGD and T Basic tutuorial
GD and T Basic tutuorial
Deenesh Savdekar
 

What's hot (20)

Fracture mechanics
Fracture mechanicsFracture mechanics
Fracture mechanics
 
Casting
CastingCasting
Casting
 
Abrasive jet machining
Abrasive jet machiningAbrasive jet machining
Abrasive jet machining
 
Ultrasonic Machining by Ms Shikha Kashyap
Ultrasonic Machining by Ms Shikha KashyapUltrasonic Machining by Ms Shikha Kashyap
Ultrasonic Machining by Ms Shikha Kashyap
 
Theory of Metal Cutting
Theory of Metal CuttingTheory of Metal Cutting
Theory of Metal Cutting
 
PERFORMANCE AND ANALYSIS OF MILLING TOOLS DYNAMOMETER
	PERFORMANCE AND ANALYSIS OF MILLING TOOLS DYNAMOMETER	PERFORMANCE AND ANALYSIS OF MILLING TOOLS DYNAMOMETER
PERFORMANCE AND ANALYSIS OF MILLING TOOLS DYNAMOMETER
 
Hermite cubic spline curve
Hermite cubic spline curveHermite cubic spline curve
Hermite cubic spline curve
 
Camtools presentation 14 15
Camtools presentation 14 15Camtools presentation 14 15
Camtools presentation 14 15
 
Cnc program writing
Cnc program writingCnc program writing
Cnc program writing
 
Finite Element Analysis - UNIT-1
Finite Element Analysis - UNIT-1Finite Element Analysis - UNIT-1
Finite Element Analysis - UNIT-1
 
two degree of freddom system
two degree of freddom systemtwo degree of freddom system
two degree of freddom system
 
Electro Chemical Grinding & Electro Chemical Honing processes
Electro Chemical Grinding & Electro Chemical Honing processesElectro Chemical Grinding & Electro Chemical Honing processes
Electro Chemical Grinding & Electro Chemical Honing processes
 
Me8097 non destructive testing and evaluation
Me8097 non destructive testing and evaluationMe8097 non destructive testing and evaluation
Me8097 non destructive testing and evaluation
 
Electron beam micromachining
Electron beam micromachiningElectron beam micromachining
Electron beam micromachining
 
ED7104 VAC_notes
ED7104 VAC_notesED7104 VAC_notes
ED7104 VAC_notes
 
Magnestic abrasive finishing process
Magnestic abrasive finishing processMagnestic abrasive finishing process
Magnestic abrasive finishing process
 
Advanced machining processes
Advanced machining processesAdvanced machining processes
Advanced machining processes
 
Sheet metal process unit 4 notes
Sheet metal process unit 4 notesSheet metal process unit 4 notes
Sheet metal process unit 4 notes
 
Fundamentals of metal forming processes
Fundamentals of metal forming processesFundamentals of metal forming processes
Fundamentals of metal forming processes
 
GD and T Basic tutuorial
GD and T Basic tutuorialGD and T Basic tutuorial
GD and T Basic tutuorial
 

Similar to Matlab assignment

Cs580
Cs580Cs580
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
Shakil 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 Design
V Tripathi
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
Saurabh 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 Problems
Sunil Yadav
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
Shakil 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 Oscillator
Abhranil Das
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
Kandarp Tiwari
 
Matlab file
Matlab file Matlab file
Matlab file
rampal singh
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
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).pdf
Neeraj381934
 
Basic python programs
Basic python programsBasic python programs
Basic python programs
RaginiJain21
 
L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
happycocoman
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
Prianka Padmanaban
 

Similar to 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-18x
week-18xweek-18x
week-18x
 
week-17x
week-17xweek-17x
week-17x
 
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
 

More from Rutvik

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

More from 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
 

Recently uploaded

Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 

Recently uploaded (20)

Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 

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