0% found this document useful (0 votes)
161 views3 pages

H1038 Programming For Engineers: Instructions

This document provides instructions for a programming assignment involving solving 6 problems in MATLAB. Students are asked to write a report of no more than 2500 words presenting their MATLAB scripts, evaluation processes, and results for each problem. The problems involve plotting piecewise linear functions, calculating sums with for loops and vectorization, creating a function to calculate triangle properties, solving circuit equations in matrix form, solving a differential equation with ode45, and modeling a signal processing system in Simulink.

Uploaded by

HassanImran
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
161 views3 pages

H1038 Programming For Engineers: Instructions

This document provides instructions for a programming assignment involving solving 6 problems in MATLAB. Students are asked to write a report of no more than 2500 words presenting their MATLAB scripts, evaluation processes, and results for each problem. The problems involve plotting piecewise linear functions, calculating sums with for loops and vectorization, creating a function to calculate triangle properties, solving circuit equations in matrix form, solving a differential equation with ode45, and modeling a signal processing system in Simulink.

Uploaded by

HassanImran
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

Programming for Engineers (2019/2020)

H1038 Programming for Engineers

Instructions

Write a report on solving the following problems using MATLAB. The report MUST NOT
exceed 2500 words (MATLAB scripts are not included in the word count). The report must
include MATLAB scripts, evaluation (testing) process of the scripts, and results. Also discuss
and comment on main MATLAB commands and functions used for solving each problem in
the report. The report should be well presented, for example each figure must have a title
and a number, and figures must be referred to in the report.

Presentation of the report [10 Marks]

Problem 1 [15 Marks]

Write a script to evaluate the following piecewise linear function.

a) ask user to input x values (using input in-built function)


b) test your code for each case and display the results

200 𝑤ℎ𝑒𝑛 𝑥 < 0


2(𝑥 + 100) 𝑤ℎ𝑒𝑛 0 ≤ 𝑥 ≤ 50
𝑦= 𝑥
6𝑥 − +1 𝑤ℎ𝑒𝑛 50 < 𝑥 < 100
50
{ 599 𝑤ℎ𝑒𝑛 𝑥 ≥ 100

Then plot y vs x for -10 ≤ x ≤ 150 on a single figure.

Problem 2 [15 Marks]

Write MATLAB scripts to find the following sums

a) with for loops


b) by vectorisation
c) Time both versions in each case and show which program runs faster

12 + 22 + 32 + ⋯ + 2

1 1 1 1 1 1 1
1− + − + − + …
2 3 4 5 6 7 

Where  is your candidate number.

Problem 3 [15 Marks]

The distance (length) between any two points (x1, y1) and (x2, y2) is:

𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒 = √(𝑥1 − 𝑥2)2 + (𝑦1 − 𝑦2)2

1
The area of a triangle is:

𝐴𝑟𝑒𝑎 = √𝑠(𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐)

𝑎+𝑏+𝑐
where a, b, c are the lengths of three edges of triangle, and 𝑠 = .
2

a) create a function which can calculate, return the lengths of three edges of a triangle
and its area. (note: must use only one function in this problem)
b) write a script that ask user to enter x and y coordinates of three vertices of a triangle,
then use the function in a) to display the lengths of three edges and area of the
triangle

Problem 4 [15 Marks]

The voltages V1, V2 and V3 of a circuit are expressed as:

𝑉1 + 2𝑉3 = 6

−6𝑉1 + 10𝑉2 − 3𝑉3 = 2

−𝑉2 + 5𝑉3 = 3

Write a MATLAB script to find V1, V2 and V3 in matrix form 𝐴𝑥 = 𝑏.

a) the script must ask user to input the coefficient matrix A and vector b
b) the script must display the determinant of A, inner dimensions of A-1×b
c) the script must check whether determinant of A is not zero and the inner dimensions
of two matrices A-1×b are the same before the script calculate the roots using the
matrices
d) the script must display the values of V1, V2 and V3

Problem 5 [15 Marks]

Response of the system y varies with time t, satisfies the differential equation

𝑑2 𝑦 𝑑𝑦
+ 10 + 16𝑦 = 16
𝑑𝑡 2 𝑑𝑡
𝑑𝑦
a) use MATLAB ode45 to solve the equation with initial values 𝑦 = 0 and 𝑑𝑡
= 0 when
𝑡 = 0. Time t is between 0 and (your candidate number)/25000
𝑑𝑦
b) use MATLAB script to find and display the maximum values of y and 𝑑𝑡
with their
corresponding time t
c) use MATLAB script to plot y vs t with correct labels
𝑑𝑦
d) use MATLAB script to plot vs t with correct labels
𝑑𝑡

Problem 6 [15 Marks]

2
A process adds signals A and B together to generate an output signal C.

𝐴 = 5𝑠𝑖𝑛 ( 𝑡) + sin(𝑡)
20000

𝐵 = 10𝑐𝑜𝑠 ( 𝑡) − cos(𝑡)
30000

Where  is your candidate number, and t is time

a) use MATLAB Simulink to model this process when 0 ≤ 𝑡 ≤ 10 seconds, the model
must be shown in the report
b) display all the positive values of signal C on a scope
c) all signals in the system must be displayed on scopes and shown in the report
d) the Simulink model and the properties of blocks must be shown in the report

You might also like