UNIVERSITI MALAYSIA SARAWAK
FACULTY OF ENGINEERING
CIVIL ENGINEERING DEPARTMENT
KNS1482 SEMESTER 2
CIVIL ENGINEERING PROGRAMMING
Assignment Titled: Final Project Assignment Programming
Lecturer: Dr. Fauzan bin Sahdi
Group Members: 1. Esther Melanie Sum (104059)
2. Nurain Batrisyia Binti Senu (105767)
3. Martin Wong Soon Cheng (102671)
4. Ling Jie (104775)
5. Nadzirah Binti Rasaie (102772)
Date of submission: 28/6/2025
1
TABLE OF CONTENTS:
INTRODUCTION 3
OBJECTIVE 4
RESULT
MATLAB Script and Coding 5-10
MATLAB Graph. 11
PSEUDOCODE 12
DISCUSSION 13
CONCLUSION 14
REFERENCES 15
APPENDIX 16
2
INTRODUCTION:
In structural engineering design, deflection can be defined as the structural response
to external forces, resulting in the changes of positions in the material. It can happen in any
type of structural element, including columns, plates and beams. Engineers need to
understand deflection as it helps to identify how much a structure will deform under various
load conditions, making it easier for them to design a safer and reliable infrastructure and
buildings (Myre, 2024). Shear force refers to the internal force that acts parallel to the
cross-section of a structural member, causing it to deform or fail. It is an essential
consideration in understanding the structural behaviour and ensuring the safety and stability
of construction elements (BYJU’S, 2023). The internal resistance of a structure to bending is
called a bending moment, which is caused by external forces acting on structural members
(Shumak, 2024).
It is essential to understand how beams react to loads to ensure safety and stability in
construction. In this project, the focus is to analyse the I-section of a steel beam fixed at one
end and subjected to time that varies from 0 to 750 seconds on distributed load uniformly.
The purpose of this project is to investigate the behaviour of deflection, shear force and
bending moment, where the length of a beam span is 10 meter using MATLAB. The
distributed load is defined as a cosine function of time. To visualize the behaviour of these
internal forces, change over time, this project involves creating animated plots. This is based
on input parameters such as cross-sectional dimensions and material properties. Also, it is to
calculate the moment of inertia using custom-made functions and to export the deflection,
shear, and moment peak values into .xls files for further evaluation. This simulation can also
deepen our understanding of structural behaviour and enhance our programming skills.
3
OBJECTIVE:
1. To construct animated plots of the distributions of shear force, bending moment and
deflection along the beam span using MATLAB.
2. To calculate the total moment of inertia of the beam cross-section using custom-made
functions.
3. To apply the function q = acos(3tπ/T) where a is the average last digit of the group
members’ matric numbers.
4. To enable the MATLAB code to accept parameter inputs (beam cross-section
dimensions, span, etc.) through the Command Window.
5. To export and save the deflection, shear force and bending moment along the beam
span in .xls file format for any peak q magnitude.
4
MATLAB SCRIPT and CODING:
% ==============================
% main_beam_analysis.m
% ==============================
clc; clear;
%% === USER INPUT ===
L = input('Enter beam length L (m): ');
bf = input('Enter flange width bf (mm): ');
tf = input('Enter flange thickness tf (mm): ');
bw = input('Enter web width bw (mm): ');
hw = input('Enter web height hw (mm): ');
a = input('Enter load amplitude a (in kN/m): ');
% Convert to meters
bf_m = bf / 1000;
tf_m = tf / 1000;
bw_m = bw / 1000;
hw_m = hw / 1000;
E = 270e9; % Pa
T = 75; % Period in seconds
t = [Link]; % Time vector
x = linspace(0, L, 100);
%% === MOMENT OF INERTIA FUNCTION ===
I = getMomentOfInertia(bf_m, tf_m, bw_m, hw_m);
%% === PEAK LOAD CALCULATION ===
q_peak = a * 1000; % Convert kN/m to N/m
Vmax = q_peak * L;
Mmax = q_peak * L^2 / 2;
ymax = q_peak * L^4 / (8 * E * I);
fprintf('\n--- PEAK VALUES ---\n');
fprintf('Moment of Inertia : %.4e m^4\n', I);
fprintf('Peak Shear Force : %.2f N\n', Vmax);
fprintf('Peak Bending Moment : %.2f Nm\n', Mmax);
fprintf('Peak Deflection (center) : %.2f mm (DOWNWARD)\n\n', ymax * 1000);
%% === ANIMATION PLOT ===
figure;
5
for i = 1:length(t)
q = a * cos(3*pi*t(i)/T) * 1000; % N/m
V = q*(L/2) - q*x;
M = (q*L/12)*(6*x - L);
y = -(q * x.^2) .* (L^2 - x.^2 - 2*L*x) / (24 * E * I);
subplot(3,1,1);
plot(x, V, 'b', 'LineWidth', 2);
title(sprintf('Shear Force (t = %ds)', t(i)));
ylabel('V (N)');
ylim([min(V) max(V)]);
grid on;
subplot(3,1,2);
plot(x, M, 'r', 'LineWidth', 2);
title('Bending Moment');
ylabel('M (Nm)');
ylim([min(M) max(M)]);
grid on;
subplot(3,1,3);
plot(x, y*1000, 'g', 'LineWidth', 2);
title('Deflection');
ylabel('y (mm)'); xlabel('x (m)');
dy = max(abs(y*1000));
ylim([-dy dy]);
grid on;
drawnow;
pause(0.05);
end
%% === SAVE RESULTS AT PEAK LOAD ===
V = -q * (L - x);
M = -q * (L - x).^2 / 2;
y = -(q * x.^2 .* (6*L^2 - 4*L*x + x.^2)) / (24 * E * I);
data = table(x', V', M', y', ...
'VariableNames', {'x_m', 'Shear_N', 'Moment_Nm', 'Deflection_m'});
filename = sprintf('beam_peak_q_%.[Link]', a);
writetable(data, filename);
6
fprintf('Results at peak load saved to %s\n', filename);
————————————————————————————————————-
function I = getMomentOfInertia(bf, tf, bw, hw)
% Compute total moment of inertia using composite method
Af = bf * tf; % Flange area
Aw = bw * hw; % Web area
A_total = 2*Af + Aw;
h_total = 2*tf + hw;
% Centroid location from bottom
y_bar = (Af*(tf/2) + Aw*(tf + hw/2) + Af*(tf + hw + tf/2)) / A_total;
% Moments of inertia about individual centroids
If = (bf * tf^3) / 12;
Iw = (bw * hw^3) / 12;
% Distances from centroidal axis
d_top = abs((h_total - tf/2) - y_bar);
d_bot = abs(y_bar - tf/2);
d_web = abs((tf + hw/2) - y_bar);
% Apply parallel axis theorem
I = If + Af*d_bot^2 + Iw + Aw*d_web^2 + If + Af*d_top^2;
end
x_m Shear_N Moment_Nm Deflection_m
0 -48000 -240000 -0
0.101010101 -47515.15152 -235176.0024 -0.0000995294797
0.202020202 -47030.30303 -230400.9795 -0.000395439308
0.303030303 -46545.45455 -225674.9311 -0.00088374224
0.404040404 -46060.60606 -220997.8574 -0.00156049192
0.505050505 -45575.75758 -216369.7582 -0.00242178291
0.606060606 -45090.90909 -211790.6336 -0.00346375062
0.707070707 -44606.06061 -207260.4836 -0.00468257141
0.808080808 -44121.21212 -202779.3082 -0.0060744625
0.909090909 -43636.36364 -198347.1074 -0.00763568201
1.01010101 -43151.51515 -193963.8812 -0.00936252897
1.111111111 -42666.66667 -189629.6296 -0.0112513433
7
1.212121212 -42181.81818 -185344.3526 -0.0132985057
1.313131313 -41696.9697 -181108.0502 -0.0155004381
1.414141414 -41212.12121 -176920.7224 -0.0178536029
1.515151515 -40727.27273 -172782.3691 -0.0203545036
1.616161616 -40242.42424 -168692.9905 -0.0229996847
1.717171717 -39757.57576 -164652.5865 -0.0257857315
1.818181818 -39272.72727 -160661.157 -0.02870927
1.919191919 -38787.87879 -156718.7022 -0.0317669674
2.02020202 -38303.0303 -152825.2219 -0.0349555317
2.121212121 -37818.18182 -148980.7163 -0.0382717116
2.222222222 -37333.33333 -145185.1852 -0.041712297
2.323232323 -36848.48485 -141438.6287 -0.0452741185
2.424242424 -36363.63636 -137741.0468 -0.0489540477
2.525252525 -35878.78788 -134092.4395 -0.052748997
2.626262626 -35393.93939 -130492.8069 -0.0566559197
2.727272727 -34909.09091 -126942.1488 -0.0606718101
2.828282828 -34424.24242 -123440.4653 -0.0647937032
2.929292929 -33939.39394 -119987.7564 -0.0690186752
3.03030303 -33454.54545 -116584.022 -0.0733438429
3.131313131 -32969.69697 -113229.2623 -0.0777663642
3.232323232 -32484.84848 -109923.4772 -0.0822834376
3.333333333 -32000 -106666.6667 -0.0868923029
3.434343434 -31515.15152 -103458.8307 -0.0915902406
3.535353535 -31030.30303 -100299.9694 -0.0963745719
3.636363636 -30545.45455 -97190.08264 -0.101242659
3.737373737 -30060.60606 -94129.17049 -0.106191906
3.838383838 -29575.75758 -91117.23294 -0.111219756
3.939393939 -29090.90909 -88154.26997 -0.116323694
4.04040404 -28606.06061 -85240.2816 -0.121501246
4.141414141 -28121.21212 -82375.26783 -0.126749979
4.242424242 -27636.36364 -79559.22865 -0.1320675
4.343434343 -27151.51515 -76792.16406 -0.137451459
4.444444444 -26666.66667 -74074.07407 -0.142899544
4.545454545 -26181.81818 -71404.95868 -0.148409486
4.646464646 -25696.9697 -68784.81788 -0.153979056
4.747474747 -25212.12121 -66213.65167 -0.159606066
4.848484848 -24727.27273 -63691.46006 -0.165288369
4.949494949 -24242.42424 -61218.24304 -0.171023859
5.050505051 -23757.57576 -58794.00061 -0.176810472
5.151515152 -23272.72727 -56418.73278 -0.182646182
5.252525253 -22787.87879 -54092.43955 -0.188529006
8
5.353535354 -22303.0303 -51815.12091 -0.194457002
5.454545455 -21818.18182 -49586.77686 -0.200428268
5.555555556 -21333.33333 -47407.40741 -0.206440944
5.656565657 -20848.48485 -45277.01255 -0.212493209
5.757575758 -20363.63636 -43195.59229 -0.218583285
5.858585859 -19878.78788 -41163.14662 -0.224709433
5.95959596 -19393.93939 -39179.67554 -0.230869957
6.060606061 -18909.09091 -37245.17906 -0.2370632
6.161616162 -18424.24242 -35359.65718 -0.243287547
6.262626263 -17939.39394 -33523.10989 -0.249541424
6.363636364 -17454.54545 -31735.53719 -0.255823296
6.464646465 -16969.69697 -29996.93909 -0.262131672
6.565656566 -16484.84848 -28307.31558 -0.2684651
6.666666667 -16000 -26666.66667 -0.274822167
6.767676768 -15515.15152 -25074.99235 -0.281201506
6.868686869 -15030.30303 -23532.29262 -0.287601786
6.96969697 -14545.45455 -22038.56749 -0.294021719
7.070707071 -14060.60606 -20593.81696 -0.300460059
7.171717172 -13575.75758 -19198.04102 -0.306915598
7.272727273 -13090.90909 -17851.23967 -0.313387172
7.373737374 -12606.06061 -16553.41292 -0.319873655
7.474747475 -12121.21212 -15304.56076 -0.326373963
7.575757576 -11636.36364 -14104.6832 -0.332887055
7.676767677 -11151.51515 -12953.78023 -0.339411928
7.777777778 -10666.66667 -11851.85185 -0.345947621
7.878787879 -10181.81818 -10798.89807 -0.352493214
7.97979798 -9696.969697 -9794.918886 -0.359047828
8.080808081 -9212.121212 -8839.914294 -0.365610624
8.181818182 -8727.272727 -7933.884298 -0.372180805
8.282828283 -8242.424242 -7076.828895 -0.378757615
8.383838384 -7757.575758 -6268.748087 -0.385340337
8.484848485 -7272.727273 -5509.641873 -0.391928297
8.585858586 -6787.878788 -4799.510254 -0.398520861
8.686868687 -6303.030303 -4138.353229 -0.405117436
8.787878788 -5818.181818 -3526.170799 -0.41171747
8.888888889 -5333.333333 -2962.962963 -0.418320452
8.98989899 -4848.484848 -2448.729721 -0.424925912
9.090909091 -4363.636364 -1983.471074 -0.43153342
9.191919192 -3878.787879 -1567.187022 -0.438142587
9.292929293 -3393.939394 -1199.877564 -0.444753067
9.393939394 -2909.090909 -881.5426997 -0.451364551
9
9.494949495 -2424.242424 -612.1824304 -0.457976776
9.595959596 -1939.393939 -391.7967554 -0.464589515
9.696969697 -1454.545455 -220.3856749 -0.471202584
9.797979798 -969.6969697 -97.94918886 -0.477815841
9.898989899 -484.8484848 -24.48729721 -0.484429183
10 -0 -0 -0.491042549
10
MATLAB GRAPH:
Figure 1 : graft of shear force, bending moment and deflection
11
PSEUDOCODE:
1. Start the program ;
2. Prompt user for beam dimensions and load parameters ;
3. Convert dimensions from mm to meters ;
4. Calculate moment of inertia using a custom function ;
5. Initialize time and space vectors ;
6. For each time step from 0 to 750s:
a. Calculate distributed load q(t),
b. Compute shear force, bending moment, and deflection,
c. Plot animated graphs,
7. Calculate peak values of internal forces and deflection ;
8. Save all results (x, shear, moment, deflection) into .xls file ;
9. End the program.
12
DISCUSSION:
In this assignment, the program was developed to calculate the total moment of inertia of the
beam cross-section, able to accept parameter input of the beam cross-section dimension and
span also to save the deflection, shear force and bending moment along the beam span in xls.
file format for any peak q magnitude. The implementation was done using Matlab, and the
logic was based on using moment of inertia equation and etc.
One of the main challenges encountered during the development process was to program an
animated graph that has time varies from 0 to 750s . To overcome this, to type the function
subplot with row and column present so that the program knows that it wants to be animated.
The program successfully achieved its intended outcome. The output produced a moving
graph of the three shears, moment and deflection as the figure shows in Matlab graph plot
section , which was consistent with theoretical expectations. The use of pause(0.05); made
the code efficient and readable.
The shear force diagram linearly decreases along the span, confirming a uniformly distributed
load. The bending moment curve shows a parabolic profile, peaking at mis-span, which is
expected in a simply supported beam under UDL. The deflection is maximum at mid-span
and follows a smooth curve, indicating proper moment of inertia calculation. The animation
also effectively visualises how the beam responds dynamically over time.
Additionally, the code allowed exporting results to .xls files enables analysis externally and
documentation. Overall, this assignment improved my understanding of both programming
logic and the underlying mathematical concepts, reinforcing the connection between
theoretical knowledge and practical implementation.
13
CONCLUSION:
In summary, we were able to create a MATLAB program that calculates the total moment of
inertia for a beam cross-section and allows the user to input their own dimensions and spans
while exporting important data such as deflection, shear force and bending moment based on
various peak load values to an Excel file. We were able to animate the diagram over a time
span of 0 to 750 seconds and create clear and dynamic visualisations, even though we found
it difficult to do so. This experience greatly improved our understanding of MATLAB
programming and the concepts of structural analysis as we effectively linked theory to
real-world application.
14
REFERENCES:
1. Myre, J. (2024, November 15). Understanding deflection in Structural Engineering:
calculation, illustration, and design implications. StruCalc.
[Link]
ortant%20concept,safety%20and%20stability%20of%20structures.
2. Shumak, Y. (2024, October 15). What is a Bending Moment? Definition, Calculation,
and Diagrams. SDC Verifier.
[Link]
3. BYJU’S. (2023, July 5). Shear force. BYJUS. Retrieved June 22, 2025.
[Link]
ts%20depending%20on%20the%20context
15
APPENDIX:
Figure 2 : Group Discussion at Petary
Figure 3: Calculation of moment of inertia
Figure 4: Whatsapp task divisions
16