0% found this document useful (0 votes)
222 views

Welding Matlab Code

The document describes a MATLAB code for analyzing stresses in an object with a given geometry. The code allows the user to input the number of corner points, loads, and moments applied to the object. It then calculates the geometry center, segment lengths, area moments of inertia, stresses, and maximum stress to check against the factor of safety. Curved segments can also be defined and accounted for in the calculations.

Uploaded by

venkat27081995
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
222 views

Welding Matlab Code

The document describes a MATLAB code for analyzing stresses in an object with a given geometry. The code allows the user to input the number of corner points, loads, and moments applied to the object. It then calculates the geometry center, segment lengths, area moments of inertia, stresses, and maximum stress to check against the factor of safety. Curved segments can also be defined and accounted for in the calculations.

Uploaded by

venkat27081995
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 16

clear all

clc
n=input('No. of corner points :'); %right hand rule
fx=input('Load fx at cg');
fy=input('Load fy at cg');
fz=input('Load fz at cg');
mx=input('Moment mx at cg');
my=input('Moment my at cg');
mz=input('Moment mz at cg');
dd=input('fos 1.25 or 1.5');
c=input('by graph 1 or by manual 2 or by graph and curves are there 3');
if c==1
xl=input('Lower x limit');
yl=input('Lower y limit');
xu=input('Upper x limit');
yu=input('Upper y limit');
[x,y]=ginputextra(n,xl,yl,xu,yu);
for i=1:n-1
lcg(i,1)=(x(i)+x(i+1))/2;
lcg(i,2)=(y(i)+y(i+1))/2;
end
for j=1:n-1
l(j)=(sqrt((((x(j+1))-(x(j)))^2)+(((y(j+1))-(y(j)))^2)));
end
elseif c==2
%
x=[0,50,50,30,30,27.5000000000000,27.5000000000000,22.5000000000000,22.500000000000
0,20,20,0,0]
% y=[0,0,10,10,60,60,70,70,60,60,10,10,0]
for j = 1:n-1
x(j)=input('starting coordinate of element X axis');
y(j)=input('starting coordinate of element Y axis');
x(j+1)=input('ending coordinate of element X axis');
y(j+1)=input('ending coordinate of element Y axis');
end
for i=1:n-1
lcg(i,1)=(x(i)+x(i+1))/2;
lcg(i,2)=(y(i)+y(i+1))/2;
end
for j=1:n-1
l(j)=(sqrt((((x(j+1))-(x(j)))^2)+(((y(j+1))-(y(j)))^2)));
end
else
xl=input('Lower x limit');
yl=input('Lower y limit');
xu=input('Upper x limit');
yu=input('Upper y limit');
[x,y]=ginputextra(n,xl,yl,xu,yu);
nc=input('No.of Curves');
for i=1:nc
cu(i,1)=input('curve start point');
cu(i,2)=input('curve end point');
cu(i,3)=input('radius of the curve');
cu(i,4)=input('type of curve 1 - qua cir, 2 - semi cir, 3 - cir');
cu(i,5)=input('if qua cir quadrant no (1,2,3,4) or if semi cir top or bot
(5,6) or full circle (7)');
end
for i=1:n-1
ma(i,1)=i;
ma(i,2)=i+1;
ma(i,3)=0;
ma(i,4)=0;
ma(i,5)=0;
end
for i=1:nc
ma(cu(i,1),:)=cu(i,:);
end
for i=1:n-1
lcg(i,1)=(x(i)+x(i+1))/2;
lcg(i,2)=(y(i)+y(i+1))/2;
end
for j=1:n-1
l(j)=(sqrt((((x(j+1))-(x(j)))^2)+(((y(j+1))-(y(j)))^2)));
end
for i=1:n-1
if ma(i,3)==0
MA(i,1)=lcg(i,1);
MA(i,2)=lcg(i,2);
else
if ma(i,5)==1
if x(i)<x(i+1)
MA(i,1)=x(i)+(2*(ma(i))/pi);
MA(i,2)=y(i+1)+(2*(ma(i))/pi);
l(i)=1.57*ma(i);
else
MA(i,1)=x(i+1)+(2*(ma(i))/pi);
MA(i,2)=y(i)+(2*(ma(i))/pi);
l(i)=1.57*ma(i);
end
elseif ma(i,5)==2
if x(i)<x(i+1)
MA(i,1)=x(i)+((ma((i)))-(2*(ma(i))/pi));
MA(i,2)=y(i)+(2*(ma(i))/pi);
l(i)=1.57*ma(i);
else
MA(i,1)=x(i+1)+((ma((i)))-(2*(ma(i))/pi));
MA(i,2)=y(i+1)+(2*(ma(i))/pi);
l(i)=1.57*ma(i);
end
elseif ma(i,5)==3
if x(i)<x(i+1)
MA(i,1)=x(i)+(ma((i)))-(2*(ma(i))/pi);
MA(i,2)=y(i+1)+(ma((i)))-(2*(ma(i))/pi);
l(i)=1.57*ma(i);
else
MA(i,1)=x(i+1)+(ma((i)))-(2*(ma(i))/pi);
MA(i,2)=y(i)+(ma((i)))-(2*(ma(i))/pi);
l(i)=1.57*ma(i);
end
elseif ma(i,5)==4
if x(i)<x(i+1)
MA(i,1)=x(i)+(2*(ma(i))/pi);
MA(i,2)=y(i)+(ma((i)))-(2*(ma(i))/pi);
l(i)=1.57*ma(i);
else
MA(i,1)=(i+1)+(2*(ma(i))/pi);
MA(i,2)=y(i+1)+(ma((i)))-(2*(ma(i))/pi);
l(i)=1.57*ma(i);
end
elseif ma(i,5)==5
MA(i,1)=2*(ma(i))/pi;
MA(i,2)=2*(ma(i))/pi;
elseif ma(i,5)==6
MA(i,1)=2*(ma(i))/pi;
MA(i,2)=2*(ma(i))/pi;
else
MA(i,1)=2*(ma(i))/pi;
MA(i,2)=2*(ma(i))/pi;
end
end
lcg=MA;
end
end
nux=0;
nuy=0;
de=0;
for i=1:n-1
nux=nux+(l(i)*lcg(i,1));
de=de+l(i);
nuy=nuy+(l(i)*lcg(i,2));
end
gcg(1,1)=nux/de;
gcg(1,2)=nuy/de;
for i=1:n-1
m(i)=((y(i+1)-y(i))/(x(i+1)-x(i)));
end
for i=1:n-1
m(i)=atan(m(i));
m(i)=57.2958*m(i);
end
% for i=1:n-1
% liyy(i)=((l(i))^3)/12;
% lixx(i)=0;
% lixy(i)=lixx(i)+liyy(i);
% end
b=1;
for i=1:n-1
% Lixx(i)=(((lixx+liyy)/2)+(((lixx-liyy)/2)*cosd(2*(90-(m(i)))))+(lixy*sind(2*(90-
m(i)))));
% Liyy(i)=(((lixx+liyy)/2)-(((lixx-liyy)/2)*cosd(2*((90-m(i)))))-(lixy*sind(2*(90-
m(i)))));
Lixx(i)=((b*l(i)/12)*((l(i)*l(i)*cosd(90-m(i))*cosd(90-m(i)))+(0*b*sind(90-
m(i))*sind(90-m(i)))));
Liyy(i)=((b*l(i)/12)*((l(i)*l(i)*cosd(180-m(i))*cosd(180-m(i)))+(0*b*sind(180-
m(i))*sind(180-m(i)))));

end
for i=1:n-1
gixx(i)=Lixx(i)+(l(i)*(lcg(i,2)-gcg(1,2))^2);
giyy(i)=Liyy(i)+(l(i)*(lcg(i,1)-gcg(1,1))^2);
gixy(i)=gixx(i)+giyy(i);
end
Gixx=sum(gixx);
Giyy=sum(giyy);
Gixy=sum(gixy);
L=sum(l);
Fxl=fx/L; %shear
Fyl=fy/L; %shear

for i=1:n %my stresses tension


if my>=0
if gcg(1,1)<x(i)
stmy(i)=(abs(my)/Giyy)*(abs(x(i)-gcg(1,1)));
else
stmy(i)=(-1)*(abs(my)/Giyy)*(abs(x(i)-gcg(1,1)));
end
end
if my<=0
if gcg(1,1)>x(i)
stmy(i)=(abs(my)/Giyy)*(abs(gcg(1,1)-x(i)));
else
stmy(i)=(-1)*(abs(my)/Giyy)*(abs(gcg(1,1)-x(i)));
end
end
end
for i=1:n %mx stresses tension
if mx>=0
if gcg(1,2)>y(i)
stmx(i)=(abs(mx)/Gixx)*(abs(gcg(1,2)-y(i)));
else
stmx(i)=(-1)*(abs(mx)/Gixx)*(abs(gcg(1,2)-y(i)));
end
end
if mx<=0
if gcg(1,2)<y(i)
stmx(i)=(abs(mx)/Gixx)*(abs(y(i)-gcg(1,2)));
else
stmx(i)=(-1)*(abs(mx)/Gixx)*(abs(y(i)-gcg(1,2)));
end
end
end
for i=1:n
Fzl(1,i)=fz/L; %tension
end
FZ=[stmx+stmy+Fzl]; %total tension mx+my+tension
for i=1:n
if FZ(i)<0
FZ(i)=0;
end
end
for i=1:n % torsional shear
r(i)=(sqrt((((gcg(1,1))-(x(i)))^2)+(((gcg(1,2))-(y(i)))^2)));
tau(i)=(abs(mz)/Gixy)*r(i);
end
for i=1:n
mmm(i)=(y(i)-(gcg(1,2)))/(x(i)-gcg(1,1));
end
for i=1:n
mmm(i)=atan(mmm(i));
mmm(i)=57.2958*mmm(i);
end
for i=1:n
if mmm(i)<0
mmm(i)=mmm(i)*(-1);
end
end
for i=1:n
if (x(i)>gcg(1,1))&&(y(i)>gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(-1);
end
if (x(i)<gcg(1,1))&&(y(i)>gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(1);
end
if (x(i)<gcg(1,1))&&(y(i)<gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(-1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(1);
end
if (x(i)>gcg(1,1))&&(y(i)<gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(-1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(-1);
end
end
if mz<0
fxx=fxx*(-1)
end
FX=[fxx+Fxl];
FY=[fyy+Fyl];
for i=1:n
Shres(i)=sqrt((FX(i)*FX(i))+(FY(i)*FY(i)));
end

FZ
Shres
for i=1:n
Stress(i)=sqrt((FZ(i)*FZ(i))+(3*Shres(i)*Shres(i)));
end
Stress
fd=max(Stress);
t=2.449*fd*dd/420;
t

clear all
clc
n=input('No. of corner points :'); %right hand rule
fx=input('Load fx at cg');
fy=input('Load fy at cg');
fz=input('Load fz at cg');
mx=input('Moment mx at cg');
my=input('Moment my at cg');
mz=input('Moment mz at cg');
dd=input('fos 1.25 or 1.5');
c=input('by graph 1 or by manual 2 or by graph and curves are there 3');
if c==1
[XY]=Points;
XY=[XY;XY(1,:)];
XY=XY(:,2:end); %Actual points from the user
x=XY(:,1);
x=x';
y=XY(:,2);
y=y';
for i=1:n
lcg(i,1)=(x(i)+x(i+1))/2;
lcg(i,2)=(y(i)+y(i+1))/2;
end
for j=1:n
l(j)=(sqrt((((x(j+1))-(x(j)))^2)+(((y(j+1))-(y(j)))^2)));
end
elseif c==2
%
x=[0,50,50,30,30,27.5000000000000,27.5000000000000,22.5000000000000,22.500000000000
0,20,20,0,0]
% y=[0,0,10,10,60,60,70,70,60,60,10,10,0]
for j = 1:n-1
x(j)=input('starting coordinate of element X axis');
y(j)=input('starting coordinate of element Y axis');
x(j+1)=input('ending coordinate of element X axis');
y(j+1)=input('ending coordinate of element Y axis');
end
for i=1:n-1
lcg(i,1)=(x(i)+x(i+1))/2;
lcg(i,2)=(y(i)+y(i+1))/2;
end
for j=1:n-1
l(j)=(sqrt((((x(j+1))-(x(j)))^2)+(((y(j+1))-(y(j)))^2)));
end
else
[XY]=Points;
XY=[XY;XY(1,:)];
XY=XY(:,2:end); %Actual points from the user
x=XY(:,1);
x=x';
y=XY(:,2);
y=y';
nc=input('No.of Curves');
for i=1:nc
cu(i,1)=input('curve start point');
cu(i,2)=input('curve end point');
cu(i,3)=input('radius of the curve');
cu(i,4)=input('type of curve 1 - qua cir, 2 - semi cir, 3 - cir');
cu(i,5)=input('if qua cir quadrant no (1,2,3,4) or if semi cir top or bot
(5,6) or full circle (7)');
end
for i=1:n
ma(i,1)=i;
ma(i,2)=i+1;
ma(i,3)=0;
ma(i,4)=0;
ma(i,5)=0;
end
for i=1:nc
ma(cu(i,1),:)=cu(i,:);
end
for j=1:n
lcg(j,1)=(x(j)+x(j+1))/2;
lcg(j,2)=(y(j)+y(j+1))/2;
end
llcg=lcg;
for j=1:n
l(j)=(sqrt((((x(j+1))-(x(j)))^2)+(((y(j+1))-(y(j)))^2)));
end
for i=1:n
if ma(i,3)==0
MA(i,1)=lcg(i,1);
MA(i,2)=lcg(i,2);
else
if ma(i,5)==1
if x(i)<x(i+1)
MA(i,1)=x(i)+(2*(ma(i))/pi);
MA(i,2)=y(i+1)+(2*(ma(i))/pi);
l(i)=1.57*ma(i);
else
MA(i,1)=x(i+1)+(2*(ma(i))/pi);
MA(i,2)=y(i)+(2*(ma(i))/pi);
l(i)=1.57*ma(i);
end
elseif ma(i,5)==2
if x(i)<x(i+1)
MA(i,1)=x(i)+((ma((i)))-(2*(ma(i))/pi));
MA(i,2)=y(i)+(2*(ma(i))/pi);
l(i)=1.57*ma(i);
else
MA(i,1)=x(i+1)+((ma((i)))-(2*(ma(i))/pi));
MA(i,2)=y(i+1)+(2*(ma(i))/pi);
l(i)=1.57*ma(i);
end
elseif ma(i,5)==3
if x(i)<x(i+1)
MA(i,1)=x(i)+(ma((i)))-(2*(ma(i))/pi);
MA(i,2)=y(i+1)+(ma((i)))-(2*(ma(i))/pi);
l(i)=1.57*ma(i);
else
MA(i,1)=x(i+1)+(ma((i)))-(2*(ma(i))/pi);
MA(i,2)=y(i)+(ma((i)))-(2*(ma(i))/pi);
l(i)=1.57*ma(i);
end
elseif ma(i,5)==4
if x(i)<x(i+1)
MA(i,1)=x(i)+(2*(ma(i))/pi);
MA(i,2)=y(i)+(ma((i)))-(2*(ma(i))/pi);
l(i)=1.57*ma(i);
else
MA(i,1)=(i+1)+(2*(ma(i))/pi);
MA(i,2)=y(i+1)+(ma((i)))-(2*(ma(i))/pi);
l(i)=1.57*ma(i);
end
elseif ma(i,5)==5
MA(i,1)=2*(ma(i))/pi;
MA(i,2)=2*(ma(i))/pi;
elseif ma(i,5)==6
MA(i,1)=2*(ma(i))/pi;
MA(i,2)=2*(ma(i))/pi;
else
MA(i,1)=2*(ma(i))/pi;
MA(i,2)=2*(ma(i))/pi;
end
end
end
end
lcg=MA;
nux=0;
nuy=0;
de=0;
for i=1:n
nux=nux+(l(i)*lcg(i,1));
de=de+l(i);
nuy=nuy+(l(i)*lcg(i,2));
end
gcg(1,1)=nux/de;
gcg(1,2)=nuy/de;
for i=1:n-1
m(i)=((y(i+1)-y(i))/(x(i+1)-x(i)));
end
for i=1:n-1
m(i)=atan(m(i));
m(i)=57.2958*m(i);
end
% for i=1:n-1
% liyy(i)=((l(i))^3)/12;
% lixx(i)=0;
% lixy(i)=lixx(i)+liyy(i);
% end
b=1;
for i=1:n-1
% Lixx(i)=(((lixx+liyy)/2)+(((lixx-liyy)/2)*cosd(2*(90-(m(i)))))+(lixy*sind(2*(90-
m(i)))));
% Liyy(i)=(((lixx+liyy)/2)-(((lixx-liyy)/2)*cosd(2*((90-m(i)))))-(lixy*sind(2*(90-
m(i)))));
Lixx(i)=((b*l(i)/12)*((l(i)*l(i)*cosd(90-m(i))*cosd(90-m(i)))+(0*b*sind(90-
m(i))*sind(90-m(i)))));
Liyy(i)=((b*l(i)/12)*((l(i)*l(i)*cosd(180-m(i))*cosd(180-m(i)))+(0*b*sind(180-
m(i))*sind(180-m(i)))));

end
for i=1:n-1
gixx(i)=Lixx(i)+(l(i)*(lcg(i,2)-gcg(1,2))^2);
giyy(i)=Liyy(i)+(l(i)*(lcg(i,1)-gcg(1,1))^2);
gixy(i)=gixx(i)+giyy(i);
end
Gixx=sum(gixx);
Giyy=sum(giyy);
Gixy=sum(gixy);
L=sum(l);
Fxl=fx/L; %shear
Fyl=fy/L; %shear

for i=1:n %my stresses tension


if my>=0
if gcg(1,1)<x(i)
stmy(i)=(abs(my)/Giyy)*(abs(x(i)-gcg(1,1)));
else
stmy(i)=(-1)*(abs(my)/Giyy)*(abs(x(i)-gcg(1,1)));
end
end
if my<=0
if gcg(1,1)>x(i)
stmy(i)=(abs(my)/Giyy)*(abs(gcg(1,1)-x(i)));
else
stmy(i)=(-1)*(abs(my)/Giyy)*(abs(gcg(1,1)-x(i)));
end
end
end
for i=1:n %mx stresses tension
if mx>=0
if gcg(1,2)>y(i)
stmx(i)=(abs(mx)/Gixx)*(abs(gcg(1,2)-y(i)));
else
stmx(i)=(-1)*(abs(mx)/Gixx)*(abs(gcg(1,2)-y(i)));
end
end
if mx<=0
if gcg(1,2)<y(i)
stmx(i)=(abs(mx)/Gixx)*(abs(y(i)-gcg(1,2)));
else
stmx(i)=(-1)*(abs(mx)/Gixx)*(abs(y(i)-gcg(1,2)));
end
end
end
for i=1:n
Fzl(1,i)=fz/L; %tension
end
FZ=[stmx+stmy+Fzl]; %total tension mx+my+tension
for i=1:n
if FZ(i)<0
FZ(i)=0;
end
end
for i=1:n % torsional shear
r(i)=(sqrt((((gcg(1,1))-(x(i)))^2)+(((gcg(1,2))-(y(i)))^2)));
tau(i)=(abs(mz)/Gixy)*r(i);
end
for i=1:n
mmm(i)=(y(i)-(gcg(1,2)))/(x(i)-gcg(1,1));
end
for i=1:n
mmm(i)=atan(mmm(i));
mmm(i)=57.2958*mmm(i);
end
for i=1:n
if mmm(i)<0
mmm(i)=mmm(i)*(-1);
end
end

for i=1:n
if (x(i)>gcg(1,1))&&(y(i)>gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(-1);
end
if (x(i)<gcg(1,1))&&(y(i)>gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(1);
end
if (x(i)<gcg(1,1))&&(y(i)<gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(-1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(1);
end
if (x(i)>gcg(1,1))&&(y(i)<gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(-1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(-1);
end
end
if mz<0
fxx=fxx*(-1)
end
FX=[fxx+Fxl];
FY=[fyy+Fyl];
for i=1:n
Shres(i)=sqrt((FX(i)*FX(i))+(FY(i)*FY(i)));
end

FZ
Shres
for i=1:n
Stress(i)=sqrt((FZ(i)*FZ(i))+(3*Shres(i)*Shres(i)));
end
Stress
fd=max(Stress);
t=2.449*fd*dd/420;
t

clear all
clc
n=input('No. of corner points :'); %right hand rule
fx=input('Load fx at cg');
fy=input('Load fy at cg');
fz=input('Load fz at cg');
mx=input('Moment mx at cg');
my=input('Moment my at cg');
mz=input('Moment mz at cg');
dd=input('fos 1.25 or 1.5');
c=input('by graph 1 or by manual 2 or by graph and curves are there 3');
if c==1
[XY]=Points;
XY=[XY;XY(1,:)];
XY=XY(:,2:end); %Actual points from the user
x=XY(:,1);
x=x';
y=XY(:,2);
y=y';
for i=1:n
lcg(i,1)=(x(i)+x(i+1))/2;
lcg(i,2)=(y(i)+y(i+1))/2;
end
for j=1:n
l(j)=(sqrt((((x(j+1))-(x(j)))^2)+(((y(j+1))-(y(j)))^2)));
end
elseif c==2
%
x=[0,50,50,30,30,27.5000000000000,27.5000000000000,22.5000000000000,22.500000000000
0,20,20,0,0]
% y=[0,0,10,10,60,60,70,70,60,60,10,10,0]
for j = 1:n-1
x(j)=input('starting coordinate of element X axis');
y(j)=input('starting coordinate of element Y axis');
x(j+1)=input('ending coordinate of element X axis');
y(j+1)=input('ending coordinate of element Y axis');
end
for i=1:n-1
lcg(i,1)=(x(i)+x(i+1))/2;
lcg(i,2)=(y(i)+y(i+1))/2;
end
for j=1:n-1
l(j)=(sqrt((((x(j+1))-(x(j)))^2)+(((y(j+1))-(y(j)))^2)));
end
else
[XY]=Points;
XY=[XY;XY(1,:)];
XY=XY(:,2:end); %Actual points from the user
x=XY(:,1);
x=x';
y=XY(:,2);
y=y';
nc=input('No.of Curves');
for i=1:nc
cu(i,1)=input('curve start point');
cu(i,2)=input('curve end point');
cu(i,3)=input('radius of the curve');
cu(i,4)=input('type of curve 1 - qua cir, 2 - semi cir, 3 - cir');
cu(i,5)=input('if qua cir quadrant no (1,2,3,4) or if semi cir top or bot,
right or left(5,6,7,8) or full circle (7)');
end
for i=1:n
ma(i,1)=i;
ma(i,2)=i+1;
ma(i,3)=0;
ma(i,4)=0;
ma(i,5)=0;
end
for i=1:nc
ma(cu(i,1),:)=cu(i,:);
end
for j=1:n
lcg(j,1)=(x(j)+x(j+1))/2;
lcg(j,2)=(y(j)+y(j+1))/2;
end
llcg=lcg;
for j=1:n
l(j)=(sqrt((((x(j+1))-(x(j)))^2)+(((y(j+1))-(y(j)))^2)));
end
for i=1:n
if ma(i,3)==0
MA(i,1)=lcg(i,1);
MA(i,2)=lcg(i,2);
else
if ma(i,5)==1
if x(i)<x(i+1)
MA(i,1)=x(i)+(2*(ma(i,3))/pi);
MA(i,2)=y(i+1)+(2*(ma(i,3))/pi);
l(i)=1.57*ma(i,3);
else
MA(i,1)=x(i+1)+(2*(ma(i,3))/pi);
MA(i,2)=y(i)+(2*(ma(i,3))/pi);
l(i)=1.57*ma(i,3);
end
elseif ma(i,5)==2
if x(i)<x(i+1)
MA(i,1)=x(i)+((((ma(i,3)))-(2*(ma(i,3))/pi)));
MA(i,2)=y(i)+(2*(ma(i,3))/pi);
l(i)=1.57*ma(i,3);
else
MA(i,1)=x(i+1)+((((ma(i,3)))-(2*(ma(i,3))/pi)));
MA(i,2)=y(i+1)+(2*(ma(i,3))/pi);
l(i)=1.57*ma(i,3);
end
elseif ma(i,5)==3
if x(i)<x(i+1)
MA(i,1)=x(i)+((((ma(i,3)))-(2*(ma(i,3))/pi)));
MA(i,2)=y(i+1)+((((ma(i,3)))-(2*(ma(i,3))/pi)));
l(i)=1.57*ma(i,3);
else
MA(i,1)=x(i+1)+((((ma(i,3)))-(2*(ma(i,3))/pi)));
MA(i,2)=y(i)+((((ma(i,3)))-(2*(ma(i,3))/pi)));
l(i)=1.57*ma(i,3);
end
elseif ma(i,5)==4
if x(i)<x(i+1)
MA(i,1)=x(i)+(2*(ma(i,3))/pi);
MA(i,2)=y(i)+((((ma(i,3)))-(2*(ma(i,3))/pi)));
l(i)=1.57*ma(i,3);
else
MA(i,1)=(i+1)+(2*(ma(i,3))/pi);
MA(i,2)=y(i+1)+((((ma(i,3)))-(2*(ma(i,3))/pi)));
l(i)=1.57*ma(i,3);
end
elseif ma(i,5)==5
if x(i)<x(i+1)
MA(i,1)=((x(i+1)+x(i))/2);
MA(i,2)=y(i)+((2*(ma(i,3))/pi));
l(i)=3.14*ma(i,3);
else
MA(i,1)=((x(i+1)+x(i))/2);
MA(i,2)=y(i)+((2*(ma(i,3))/pi));
l(i)=3.14*ma(i,3);
end
elseif ma(i,5)==6
if x(i)<x(i+1)
MA(i,1)=((x(i+1)+x(i))/2);
MA(i,2)=y(i)-((2*(ma(i,3))/pi));
l(i)=3.14*ma(i,3);
else
MA(i,1)=((x(i+1)+x(i))/2);
MA(i,2)=y(i)-((2*(ma(i,3))/pi));
l(i)=3.14*ma(i,3);
end
elseif ma(i,5)==7
if y(i)<y(i+1)
MA(i,1)=x(i)+((2*(ma(i,3))/pi));
MA(i,2)=((y(i+1)+y(i))/2);
l(i)=3.14*ma(i,3);
else
MA(i,1)=x(i)+((2*(ma(i,3))/pi));
MA(i,2)=((y(i+1)+y(i))/2);
l(i)=3.14*ma(i,3);
end
elseif ma(i,5)==8
if x(i)<x(i+1)
MA(i,1)=x(i)-((2*(ma(i,3))/pi));
MA(i,2)=((y(i+1)+y(i))/2);
l(i)=3.14*ma(i,3);
else
MA(i,1)=x(i)-((2*(ma(i,3))/pi));
MA(i,2)=((y(i+1)+y(i))/2);
l(i)=3.14*ma(i,3);
end
else
MA(i,1)=((x(i+1)+x(i))/2);
MA(i,2)=((y(i+1)+y(i))/2);
l(i)=2*3.14*ma(i,3);
end
end
end
end
lcg=MA;
nux=0;
nuy=0;
de=0;
for i=1:n
nux=nux+(l(i)*lcg(i,1));
de=de+l(i);
nuy=nuy+(l(i)*lcg(i,2));
end
gcg(1,1)=nux/de;
gcg(1,2)=nuy/de;
for i=1:n-1
m(i)=((y(i+1)-y(i))/(x(i+1)-x(i)));
end
for i=1:n-1
m(i)=atan(m(i));
m(i)=57.2958*m(i);
end
% for i=1:n-1
% liyy(i)=((l(i))^3)/12;
% lixx(i)=0;
% lixy(i)=lixx(i)+liyy(i);
% end
b=1;
for i=1:n-1
% Lixx(i)=(((lixx+liyy)/2)+(((lixx-liyy)/2)*cosd(2*(90-(m(i)))))+(lixy*sind(2*(90-
m(i)))));
% Liyy(i)=(((lixx+liyy)/2)-(((lixx-liyy)/2)*cosd(2*((90-m(i)))))-(lixy*sind(2*(90-
m(i)))));
Lixx(i)=((b*l(i)/12)*((l(i)*l(i)*cosd(90-m(i))*cosd(90-m(i)))+(0*b*sind(90-
m(i))*sind(90-m(i)))));
Liyy(i)=((b*l(i)/12)*((l(i)*l(i)*cosd(180-m(i))*cosd(180-m(i)))+(0*b*sind(180-
m(i))*sind(180-m(i)))));

end
for i=1:n-1
gixx(i)=Lixx(i)+(l(i)*(lcg(i,2)-gcg(1,2))^2);
giyy(i)=Liyy(i)+(l(i)*(lcg(i,1)-gcg(1,1))^2);
gixy(i)=gixx(i)+giyy(i);
end
Gixx=sum(gixx);
Giyy=sum(giyy);
Gixy=sum(gixy);
L=sum(l);
Fxl=fx/L; %shear
Fyl=fy/L; %shear

for i=1:n %my stresses tension


if my>=0
if gcg(1,1)<x(i)
stmy(i)=(abs(my)/Giyy)*(abs(x(i)-gcg(1,1)));
else
stmy(i)=(-1)*(abs(my)/Giyy)*(abs(x(i)-gcg(1,1)));
end
end
if my<=0
if gcg(1,1)>x(i)
stmy(i)=(abs(my)/Giyy)*(abs(gcg(1,1)-x(i)));
else
stmy(i)=(-1)*(abs(my)/Giyy)*(abs(gcg(1,1)-x(i)));
end
end
end
for i=1:n %mx stresses tension
if mx>=0
if gcg(1,2)>y(i)
stmx(i)=(abs(mx)/Gixx)*(abs(gcg(1,2)-y(i)));
else
stmx(i)=(-1)*(abs(mx)/Gixx)*(abs(gcg(1,2)-y(i)));
end
end
if mx<=0
if gcg(1,2)<y(i)
stmx(i)=(abs(mx)/Gixx)*(abs(y(i)-gcg(1,2)));
else
stmx(i)=(-1)*(abs(mx)/Gixx)*(abs(y(i)-gcg(1,2)));
end
end
end
for i=1:n
Fzl(1,i)=fz/L; %tension
end
FZ=[stmx+stmy+Fzl]; %total tension mx+my+tension
for i=1:n
if FZ(i)<0
FZ(i)=0;
end
end
for i=1:n % torsional shear
r(i)=(sqrt((((gcg(1,1))-(x(i)))^2)+(((gcg(1,2))-(y(i)))^2)));
tau(i)=(abs(mz)/Gixy)*r(i);
end
for i=1:n
mmm(i)=(y(i)-(gcg(1,2)))/(x(i)-gcg(1,1));
end
for i=1:n
mmm(i)=atan(mmm(i));
mmm(i)=57.2958*mmm(i);
end
for i=1:n
if mmm(i)<0
mmm(i)=mmm(i)*(-1);
end
end

for i=1:n
if (x(i)>gcg(1,1))&&(y(i)>gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(-1);
end
if (x(i)<gcg(1,1))&&(y(i)>gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(1);
end
if (x(i)<gcg(1,1))&&(y(i)<gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(-1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(1);
end
if (x(i)>gcg(1,1))&&(y(i)<gcg(1,2))
fxx(i)=(tau(i)*cosd(90-mmm(i)))*(-1);
fyy(i)=(tau(i)*cosd(mmm(i)))*(-1);
end
end
if mz<0
fxx=fxx*(-1)
end
FX=[fxx+Fxl];
FY=[fyy+Fyl];
for i=1:n
Shres(i)=sqrt((FX(i)*FX(i))+(FY(i)*FY(i)));
end
FZ
Shres
for i=1:n
Stress(i)=sqrt((FZ(i)*FZ(i))+(3*Shres(i)*Shres(i)));
end
Stress
fd=max(Stress);
t=2.449*fd*dd/420;
t

You might also like