Matlab Oel Final
Matlab Oel Final
Matlab Oel Final
SAHIWAL
SEMESTER: 7𝑡ℎ
Group Members
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
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;
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;
% 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.
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
P1=10+64 =74KN
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');
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;
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;
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
UDL=40+64=104 KN/m
Length of UDL = 4m