You are on page 1of 7

CE2602-CE2603 Sustainable Construction/Infrastructure and Professional Skills

Assignment for MATLAB Programming

Submission Deadline: 4pm on Friday 15th March 2019


What to Submit: A cover page + MATLAB programs (script files)
How to Submit: Online via WISEflow

All information required for completing this assignment can be found in ‘MATLAB Workshops’ folder on
Blackboard. It is advisable to complete all tasks in all 3 MATLAB workshops before you start this
assignment’s tasks. For additional reference, any of the following books will be adequate:
 Gilat, MATLAB: An Introduction with Applications, John Wiley & Sons; 4th Ed., 2011.
 S. Chapman, J., MATLAB Programming for Engineers, Nelson Engineering; 4th Ed., 2007.
 H. Moore, MATLAB for Engineers, Pearson Education; 3rd Ed., 2011.

MATLAB TIPS/TRICKS
 To get info and examples on how to use a function/command, use doc, e.g. >> doc interp1.
 To return to previously typed commands in ‘Command Window’, you can use “arrow up” ↑ key.
 Upper or Low Case: MATLAB is case‐sensitive. All functions must be in low cases, but variables can
be in low cases, upper cases or mixed. NO space in function and variable names.
 Location to save MATLAB script files or data: You can change work directory (folder) to any other
directory (folder) such as “H:\mywork” (see top left immediately above ‘Command Window’).

REQUIREMENT FOR PROGRAMS


 All tasks in each problem should be solved by ONE script file together with function files if required.
 All MATLAB commands should be entered into script files. No command should be entered in
MATLAB ‘Command Window’ unless it is for testing purpose.
 Use ; to suppress all intermittent results from MATLAB ‘Command Window’. However, make sure
that all final results are very clearly presented on the MATLAB ‘Command Window’ when script files
are executed.
 All plots should have titles and labels for all axes.
 To make a MATLAB program readable for other program users and yourself, it is important to
include some comments and very brief explanation throughout the program. In MATLAB % is used
to add comments. On any line of a program, anything after % will be ignored when the program is
executed. The first contiguous comment on the program becomes the script’s help file. It is a good
idea to identify main and important variables used in the beginning of any program. Please add
sufficient comments when you write the program, this will help you to avoid wasting time later
when you need to debug the program. However, it is NOT necessary to comment every line of the
program. Only comment on important lines.
 The program should only require the minimum intervention by users. If the user is required to
enter any information (e.g. enter some numbers), some clear and self‐explanatory prompts should
be presented on the MATLAB ‘Command Window’.

REQUIREMENTS FOR SUBMITTING SCRIPT FILES ON WISEflow


 All MATLAB programs (script files) must be submitted by uploading them to WiseFlow before the
aforementioned submission deadline.
 Before uploading your files, it is advisable to create a folder on your computer and put all files in
this folder and test run them within MATLAB.
 To upload your MATLAB script files to WISEflow, please first upload the prepared Cover Page
containing your name and your student’s ID, then upload all your script files. You better zip all your
script files so you can submit only one file along with the cover page. Should you require any
further help or assistance, please contact Basia Pietluch in TPO.
 Any submission after the aforementioned deadline will be considered to be a late submission and
subject to the usual College policy for late submissions.
Page 1 of 7
CE2602-CE2603 Sustainable Construction/Infrastructure and Professional Skills

Assignment for MATLAB Programming

MARKING CRITERIA
Your submission will be marked according to the following marking criteria:
[80‐100]: In addition to [70‐79], additional marks will be awarded to the quality of MATLAB
programs and explanations, for example, efficient program codes, proper in‐program
explanations/comments.
[70‐79]: All MATLAB programs are correct and correct results are produced. Program codes are
presented with proper annotations to explain the functions of the programs.
[60‐69]: The MATLAB programs related to majority of tasks are correct and correct results are
produced for majority of tasks. Program codes are presented with some explanations and
comments.
[50‐59]: The MATLAB programs related to over half of tasks are correct and correct results are
produced for over half of tasks.
[40‐49]: The MATLAB programs related to 1/3 of tasks are correct and correct results are produced
for over 1/3 of tasks.
[30‐39]: The programs fail to execute; however, some good efforts have been made to complete all
tasks. Some program codes are presented.
[0‐29]: Suitable marks will be given based on the programs produced and the effort made.

The final mark will be calculated according to the following weighting factors:
P1 P2 P3 P4 Discretionary Mark
(programs correctness and efficiency)
20% 25% 35% 10% 10%

Page 2 of 7
CE2602-CE2603 Sustainable Construction/Infrastructure and Professional Skills

Assignment for MATLAB Programming

P1. Use MATLAB to solve linear simultaneous equations

For the truss shown in the figure below, unknown forces in the members are determined
by solving the following linear equations simultaneously:

RAx FAB cos 1 FAD 0 FBC cos 2 FCD 0


RAy FAB sin 1 0 RCy FBC sin 2 0
FBC cos2 FAB cos1 F1 0 FCD FAD 0
FBD FBC sin 2 FAB sin 1 0 FBD F2 0

The applied forces are F1=32(1+0.3S) N and F2=23(1+0.2S) N. The inner angles, θ1 and
θ2 are 45° and 30°, respectively.

Use suitable MATLAB commands to solve for unknown forces RAx, RAy, RCy, FAD, FAB,
FBD, FCD, and FBC.

Note that the parameter S in F1 and F2 is a parameter related to each student’s ID and must
be generated before you start to solve this problem using the following MATLAB codes:

RandStream.setGlobalStream(RandStream('mt19937ar','seed',1234567));
S=rand(1);
Replace this with your student ID

HINTS:
 To solve system of equations, see MATLAB Tutorial (in ‘MATLAB Workshops’ folder on
Blackboard) page 13.
 If you want to present final answers with formatted texts, use fprintf command.
Find more information in MATLAB Tutorial (in ‘MATLAB Workshops’ folder on Blackboard)
page 36.

Page 3 of 7
CE2602-CE2603 Sustainable Construction/Infrastructure and Professional Skills

Assignment for MATLAB Programming

P2. Use MATLAB to solve nonlinear optimisation problems

Minimise the objective function f:

2
f (a, h) 11.25ah 7h 3

subject to the following constraints:

1300
440
ah
1546 2 (a2 h)
 100
ah 0.26
a 15 0
a 1 0
h 0.3 0
h 0.1 0

HINTS:
 Use fmincon command, see MATLAB Tutorial (in ‘MATLAB Workshops’ folder on Blackboard)
page 28.
 The objective function is a function of two variables. To solve this type of question, the objective
function must be first converted into a function of a single vector variable. The same should be
done for constraint functions.
 Basically, you need to define TWO functions, one function for the objective, another for
describing constraints. See examples for constraint optimisation in MATLAB Tutorial (in ‘MATLAB
Workshops’ folder on Blackboard) pages 28‐30.
 You need to do some preparation work to convert all constraints to the standard format so that
they can be described by the constraint function.

Page 4 of 7
CE2602-CE2603 Sustainable Construction/Infrastructure and Professional Skills

Assignment for MATLAB Programming

P3. Use MATLAB to solve complex engineering problems (differential equation


solutions, data interpretation, loop, 2-D plots and subplots)

A ball is thrown into the air with the initial velocity v0 and the angle α to horizontal
direction (see figure below).

The air is assumed to have friction which is proportional to the velocity. The horizontal
and vertical velocities and positions can be determined by solving the following
differential equations (derived from the Newton’s law):

dvx B
dt  m v x
 vx (0) v0 cos ()
dvy B

g  v
 dt m y vy (0) v0 sin ()
 
dx v x x(0) 0
dt  y(0) 0

dy  v y
dt

with m 10, B 2, g 9.81, 60(10.2S ), v 26(10.2S )


0
where S is the student related parameter generated in the same way as for P1. and P2.

P3.1 Use a differential equation solver in MATLAB (i.e. ode45, ode23 or ode15s) to solve
the above equations to find the solution for vx, vy, x, y and the corresponding time history
t for the time period of [0, 5] seconds. Plot all four graphs (vx versus t, vy versus t, x versus
t, and y versus t) in one figure window.

P3.2 Find the time (tf) when the ball strikes the ground, i.e. y=0. The way to find the time tf is
to solve the system differential equations for a longer period time (done in P3.1) and then
use interp1 to find tf when y(tf)=0.

P3.3 For the time interval [0, tf], repeat the ODE solution of P3.1 to calculate the complete time
history of t, vx, vy, x and y. Plot all four graphs (vx versus t, vy versus t, x versus t, and y
versus t) in one figure window.

Page 5 of 7
CE2602-CE2603 Sustainable Construction/Infrastructure and Professional Skills

Assignment for MATLAB Programming

P3.4 When the initial velocity changes, the time that the ball hits the ground will change. For
the following 10 different initial velocities and angles (k=1, 2, 3,…,10), determine the time
that the ball hits the ground:

v0 (k ) 26(10.2S )[10.05(k 1)]


 (k ) 60(10.2S )[10.01(k 1)]
0

Plot the times against initial horizontal velocities.

Note that S is the student related parameter generated in the same way as in P1.

HINTS:
For P3.1:
 To solve multiple 1st order differential equations, see problem W2P4 in Workshop 2 and
MATLAB Tutorial (in ‘MATLAB Workshops’ folder on Blackboard) page 32.
 The first step is to define a MATLAB function (anonymous function or function m‐file) to describe
the ball throw dynamic equations with ‘dotz’ as the function output, t (time) and z as the input.
Note that the only task for this function is to describe four differential equations in a vector
format, nothing else should be put into this function!

 To plot all four graphs in one figure window, use subplot command. See problem W1P4 in
Workshop 1 and MATLAB Tutorial (in ‘MATLAB Workshops’ folder on Blackboard) page 19.
For P3.2:
 This can be done by the interp1 and/or find command(s) (MATLAB Tutorial (in ‘MATLAB
Workshops’ folder on Blackboard) pages 47‐48). From
the graph on the right, it can be seen that no data point
at exactly y(t)=0, so that some approximations must be
made. We can find the first data point when y(t)<0 and
the last data point when y(t)>0 and then approximately
determine tf.
Method 1: Approximate with more data points
Pindex=find(y<0);
yselect=y(Pindex(1)-3:Pindex(1)+3);
tselect=t(Pindex(1)-3:Pindex(1)+3);
tf=interp1(yselect, tselect,0);
Method 2: Very rough approximation
Pindex=find(y<0);
tf=(t(Pindex(1))+t(Pindex(1)-1))/2;

For P3.4: You need to use loop for this task, see problem W3P3 in Workshop 3.

Page 6 of 7
CE2602-CE2603 Sustainable Construction/Infrastructure and Professional Skills

Assignment for MATLAB Programming

P4. MATLAB program branches

Write a MATLAB program to call all programs written for the first three problems in this
assignment. When this program is executed, a selection menu similar to the following one
should be presented:

---------------------------
Select Problem to solve:
---------------------------
1: Problem 1
2: Problem 2
3: Problem 3

Once the selection is made, the relevant program should be executed to solve the problem
selected. The program should be able to return to the selection menu before all problems
have been solved.

HINT:
Use MATLAB command switch-case-end, see problem W3P4 in Workshop 3.

Page 7 of 7

You might also like