Matlab Oel Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

QUAID-E-AZAM COLLEGE OF ENGINEERING & TECHNOLOGY

SAHIWAL

AFFILIATED WITH UNIVERSITY OF ENGINEERING &


TECHNOLOGY LAHORE

OPEN ENDED LAB

SUBJECT NAME: STRUCTURE ENGINEERING LAB

SUBMITTED BY: GROUP-II

DEPARTMENT: CIVIL ENGINEERING

SEMESTER: 7𝑡ℎ
Group Members

Names Registration No.

Muhammad Zohaib (G.L) 2018-UET-QET.SWL-CIVIL-64

Anwaar Safdar 2018-UET-QET.SWL-CIVIL-69

Muhammad Hassan ALi 2018-UET-QET.SWL-CIVIL-71

Khuzaima Ihasan 2018-UET-QET.SWL-CIVIL-76

Muhammad Hammad Arshad 2018-UET-QET.SWL-CIVIL-66


MATLAB
Introduction
MATLAB stands for matrix laboratory
 MATLAB provides a language and environment for
 numerical computation, data analysis, visualization and
 algorithm development
 MATLAB provides functions that operate on
 Integer, real and complex numbers
 Vectors and matrices
 Structures

Functionality
Built-in Functionality includes
 Matrix manipulation and linear algebra
 Mathematical computation
 Algorithm development
 Data acquisition
 Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics
Add-on toolboxes provide
 Image processing
 Signal Processing
 Optimization
 Genetic Algorithms

MATLAB paradigm
 MATLAB is an interactive environment
 Commands are interpreted one line at a time
 Commands may be scripted to create your own functions or
Procedures
 Variables are created when they are used
 Variables are typed, but variable names may be reused for
different types
 Basic data structure is the matrix
 Matrix dimensions are set dynamically

MATLAB Desktop
 Command Window: Where you enter commands
 Command History: running history of commands which is preserved across MATLAB
sessions
 Current directory: Default is $mart lab root/work
 Workspace: GUI for viewing, loading and saving MATLAB variables
 Editor/Debugger: text editor, debugger; editor works with file types in addition to .m
(MATLAB “m files”)

Operations in MATLAB
 Arithmetic Operation
 To sum up x + y <Enter>
 Subtraction x - y <Enter>
 Multiplication x * y <Enter>
 Division x / y <Enter>
 x \ y <Enter>
 Exponent x ^ y <Enter>
 Variables
Assign variables to do the arithmetic
Operations to use the result in further
calculations
Variable name consists only of:
Letters from a-z Numbers from 0-9 underscore ( _ )
It must start with a letter.
 Matrix operations
^: exponentiation
*: multiplication
/: division
\: left division. The operation A\B is effectively the same as INV(A)*B, although left
division is calculated differently and is much quicker.
+: addition
-: subtraction
 Creating Vectors and Matrices
>> A = [16 3; 5 10]
A = 16 3
5 10
>> B = [3 4 5
6 7 8]
B=3 4 5
6 7 8
 Array Operations
Evaluated element by element
 .' : array transpose
 .^ : array power
 .* : array multiplication
 ./ : array division
 Very different from Matrix operations

Simulink in MATLAB

Simulink is an environment for simulation and model-based design for dynamic and
embedded systems. It provides an interactive graphical environment and a customizable set
of block libraries that let you design, simulate, implement, and test a variety of time-varying
systems, including communications, controls, signal processing, video processing, and image
processing.
Simulink offers:
 A quick way of developing your model in contrast to text based-programming
language such as e.g., C.
 Simulink has integrated solvers. In text based-programming language such as e.g., C
you need to write your own solver

Start using Simulink


 You start Simulink from the MATLAB IDE.
 Open MATLAB and select the Simulink icon in the Toolbar
 Or type “Simulink” in the Command window, like this:

 Then the following window


appears (Simulink Library Browser):
The Simulink Library Browser is
the library where you find all the
blocks you may use in Simulink.
Simulink software includes an
extensive library of functions
commonly used in modeling a system.
These include:
 Continuous and discrete dynamics
Blocks, such as Integration, Transfer
Functions, Transport Delay, etc.
 Math blocks, such as Sum, Product,
Add, etc.
 Sources, such as Ramp, Random Generator, Step, etc.

Use of MATLAB in civil engineering


Civil engineering is a branch of engineering that is concerned with designing and constructing
public amenities such as bridges, dams, roads, and other infrastructure projects. It ranks among the
oldest fields of engineering, providing the members of the public with the facilities they need
around them. Civil engineers are technically the people who run the world. Without roads,
railways, hospitals, power and water supplies, schools, and offices, it could be extremely difficult
to travel from one place to another and obtain health care, education, and everything else provided
by these amenities. But to design and implement these public works, they have to be tested to make
sure that they indeed are going to function as desired and serve the purpose they are intended for.
This is where MATLAB comes in. MATLAB allows civil engineers to create models and designs
of the project they are about to undertake to make sure they are producing the best results. Here
are two major uses of MATLAB in civil engineering:
 Creating designs: One way through which civil engineers use MATLAB is to create
designs for the expected infrastructures and facilities. When a model of the expected
project is created prior to implementing the actual project, it helps reduce construction
costs. It also enables the engineers to find out if the final product is going to function
as desired because the design will be tested for accuracy even before it is converted
to the actual project. Having models created before the development of the final
project could also help save human lives. We have heard of million-dollar buildings
collapse and claim people’s lives just because an error was overlooked in the model
development or the testing phase. With MATLAB, there is a reduced chance for errors
because engineers can build models and test them for accuracy and effectiveness
before embarking on the real project.
 Writing code and performing numerical analysis: Creating models in civil
engineering requires complex coding and performing intricate mathematical
analysis. With MATLAB, engineers can write effective code for their simulations
with the help of Simulink software, plot variations, and work out complex matrix
equations. Many problems in civil engineering involve an advanced level of
matrices, which can be difficult to solve without MATLAB. Good knowledge of
MATLAB helps civil engineers create efficient, compact simulations to solve
engineering problems of different complexity levels. To learn how to write an
effective MATLAB code and accurately work out matrices for varying civil
engineering problems.

Specific areas where MATLAB is used in civil engineering


MATLAB has been found quite effective in the following civil engineering sub-
branches:
Transportation: While transport and traffic engineering is often done with Excel, using
MATLAB makes your work a lot easier.
Surveying: MATLAB is used in surveying and, more specifically, in leveling and calculating
the bearing
Water resources: MATLAB has been used for many years to compute fluid dynamics, an
important element in constructing dams, man-made lakes, and other water resources.
Structure analysis: MATLAB use to analyze Beam, Truss and Frame displacement, slope,
Bending Moment diagrams, Shear Force Diagram etc. It is used in basics of finite element
analysis such as adding element stiffness matrix to structure stiffness matrix.
The major reason why MATLAB is used in civil engineering is its ability to perform complex
calculations. Generally, MATLAB functions like C but it can perform more advanced
computations than C.

MATLAB Coding for SFD and BMD of given beam,


BEAM # 1:
Coding:
% This Matlab code can be used for simply supported beam with single point
% load or uniformly distributed to find the
% * Support reaction
% * Maximum Bending Moment
% * Shear force diagram
% * Bending Moment daigram
clc; clear; close all
disp('Simply Supported Beam');

% Data input section


disp(' ');
L = input('Length of beam in meter = ');
disp(' ');disp('Type 1 for point load, Type 2 for udl')
Type = input('Load case = ');

if Type == 1
disp(' ');
W = input('Load applied in kN = ');
disp(' ');
a = input('Location of Load from left end of the beam in meter = ');
c = L-a;

R1 = W*(L-a)/L; % Left Support Reaction.


R2 = W*a/L; % Right Support Reaction.

else
disp(' ');
W = input('Uniformly distributed load in kN/m = ');
disp(' ');
b = input('Length of udl in meter = ');
disp(' ');
cg = input('C.G of udl from left end of the beam in meter = ');
a = (cg-b/2);
c = L-a-b;

R1 = W*b*(b+2*c)/(2*L); % Left Support Reaction.


R2 = W*b*(b+2*a)/(2*L); % Right Support Reaction.
end

% Discretization of x axis.
n = 1000; % Number of discretization of x axis.
delta_x = L/n; % Increment for discretization of x axis.
x = (0:delta_x:L)'; % Generate column array for x-axis.

V = zeros(size(x, 1), 1); % Shear force function of x.


M = zeros(size(x, 1), 1); % Bending moment function of x.

% Data processing section


if Type == 1
for ii = 1:n+1
% First portion of the beam, 0 < x < b
V(ii) = R1;
M(ii) = R1*x(ii);
% Second portion of the beam, b < x < L
if x(ii) >= a
V(ii) = R1-W;
M(ii) = R1*x(ii)-W*(x(ii)-a);
end
end
x1 = a;
Mmax = W*a*(L-a)/L;
else
for ii = 1:n+1
% First portion of the beam, 0 < x < a
if x(ii) < a
V(ii) = R1;
M(ii) = R1*x(ii);
elseif a <= x(ii) && x(ii)< a+b
% Second portion of the beam, a < x < a+b
V(ii) = R1-W*(x(ii)-a);
M(ii) = R1*x(ii)-W*((x(ii)-a)^2)/2;
elseif x(ii) >= (a+b)
% Second portion of the beam, a+b < x < L
V(ii) = -R2;
M(ii) = R2*(L-x(ii));
end
end
x1 = a+b*(b+2*c)/(2*L);
Mmax = W*b*(b+2*c)*(4*a*L+2*b*c+b^2)/(8*L^2);
end

disp(' ');disp (['Left support Reaction' ' = ' num2str(R1) ' ' 'kN'])
disp(' ');disp (['Left support Reaction' ' = ' num2str(R2) ' ' 'kN'])
disp(' ');disp (['Maximum bending moment' ' = ' num2str(Mmax) ' ' 'kNm'])

figure
subplot(2,1,1);
plot(x, V, 'r','linewidth',1.5); % Grafica de las fuerzas cortantes.
grid
line([x(1) x(end)],[0 0],'Color','k');
line([0 0],[0 V(1)],'Color','r','linewidth',1.5);
line([x(end) x(end)],[0 V(end)],'Color','r','linewidth',1.5);
title('Shear Force Diagram','fontsize',16)
text(a/2,V(1),num2str(V(1)),'HorizontalAlignment','center','FontWeight','bold
','fontsize',16)
text((L-
c/2),V(end),num2str(V(end)),'HorizontalAlignment','center','FontWeight','bold
','fontsize',16)
axis off

subplot(2,1,2);
plot(x, M, 'r','linewidth',1.5); % Grafica de momentos flectores;
grid
line([x(1) x(end)],[0 0],'Color','k');
line([x1 x1],[0 Mmax],'LineStyle','--','Color','b');
title('Bending Moment Diagram','fontsize',16)
text(x1+1/L,Mmax/2,num2str(roundn(Mmax,-
2)),'HorizontalAlignment','center','FontWeight','bold','fontsize',16)
text(x1,0,[num2str(roundn(x1,-2)) '
m'],'HorizontalAlignment','center','FontWeight','bold','fontsize',16)
axis off
Use of Different terms;
Group leader roll no. R=64

Span length =8m

P1=10+64 =74KN

Location of Load from left end of the beam in meter =3m

Draw the SFD and BMD of Beam;


BEAM # 2:

Coding:
% This Matlab code can be used for simply supported beam with single point
% load or uniformly distributed to find the
% * Support reaction
% * Maximum Bending Moment
% * Shear force diagram
% * Bending Moment daigram
clc; clear; close all
disp('Simply Supported Beam');

% Data input section


disp(' ');
L = input('Length of beam in meter = ');
disp(' ');disp('Type 1 for point load, Type 2 for udl')
Type = input('Load case = ');

if Type == 1
disp(' ');
W = input('Load applied in kN = ');
disp(' ');
a = input('Location of Load from left end of the beam in meter = ');
c = L-a;

R1 = W*(L-a)/L; % Left Support Reaction.


R2 = W*a/L; % Right Support Reaction.

else
disp(' ');
W = input('Uniformly distributed load in kN/m = ');
disp(' ');
b = input('Length of udl in meter = ');
disp(' ');
cg = input('C.G of udl from left end of the beam in meter = ');
a = (cg-b/2);
c = L-a-b;

R1 = W*b*(b+2*c)/(2*L); % Left Support Reaction.


R2 = W*b*(b+2*a)/(2*L); % Right Support Reaction.
end
% Discretization of x axis.
n = 1000; % Number of discretization of x axis.
delta_x = L/n; % Increment for discretization of x axis.
x = (0:delta_x:L)'; % Generate column array for x-axis.

V = zeros(size(x, 1), 1); % Shear force function of x.


M = zeros(size(x, 1), 1); % Bending moment function of x.

% Data processing section


if Type == 1
for ii = 1:n+1
% First portion of the beam, 0 < x < b
V(ii) = R1;
M(ii) = R1*x(ii);

% Second portion of the beam, b < x < L


if x(ii) >= a
V(ii) = R1-W;
M(ii) = R1*x(ii)-W*(x(ii)-a);
end
end
x1 = a;
Mmax = W*a*(L-a)/L;
else
for ii = 1:n+1
% First portion of the beam, 0 < x < a
if x(ii) < a
V(ii) = R1;
M(ii) = R1*x(ii);
elseif a <= x(ii) && x(ii)< a+b
% Second portion of the beam, a < x < a+b
V(ii) = R1-W*(x(ii)-a);
M(ii) = R1*x(ii)-W*((x(ii)-a)^2)/2;
elseif x(ii) >= (a+b)
% Second portion of the beam, a+b < x < L
V(ii) = -R2;
M(ii) = R2*(L-x(ii));
end
end
x1 = a+b*(b+2*c)/(2*L);
Mmax = W*b*(b+2*c)*(4*a*L+2*b*c+b^2)/(8*L^2);
end

disp(' ');disp (['Left support Reaction' ' = ' num2str(R1) ' ' 'kN'])
disp(' ');disp (['Left support Reaction' ' = ' num2str(R2) ' ' 'kN'])
disp(' ');disp (['Maximum bending moment' ' = ' num2str(Mmax) ' ' 'kNm'])

figure
subplot(2,1,1);
plot(x, V, 'r','linewidth',1.5); % Grafica de las fuerzas cortantes.
grid
line([x(1) x(end)],[0 0],'Color','k');
line([0 0],[0 V(1)],'Color','r','linewidth',1.5);
line([x(end) x(end)],[0 V(end)],'Color','r','linewidth',1.5);
title('Shear Force Diagram','fontsize',16)
text(a/2,V(1),num2str(V(1)),'HorizontalAlignment','center','FontWeight','bold
','fontsize',16)
text((L-
c/2),V(end),num2str(V(end)),'HorizontalAlignment','center','FontWeight','bold
','fontsize',16)
axis off

subplot(2,1,2);
plot(x, M, 'r','linewidth',1.5); % Grafica de momentos flectores;
grid
line([x(1) x(end)],[0 0],'Color','k');
line([x1 x1],[0 Mmax],'LineStyle','--','Color','b');
title('Bending Moment Diagram','fontsize',16)
text(x1+1/L,Mmax/2,num2str(roundn(Mmax,-
2)),'HorizontalAlignment','center','FontWeight','bold','fontsize',16)
text(x1,0,[num2str(roundn(x1,-2)) '
m'],'HorizontalAlignment','center','FontWeight','bold','fontsize',16)
axis off

Use of Different terms;


Group leader roll no. R=64

Span length =8m

UDL=40+64=104 KN/m

Length of UDL = 4m

C.G of UDL from left end of the beam = 6m


Draw the SFD and BMD of Beam;

You might also like