You are on page 1of 2

SKTK1533 Introduction to Computer Programming 20172018-1

Exercise 4.1 (CO4): Name : ______________________________________

1. If a force F(N) is applied to compress a spring, its displacement x(cm) can often be
modelled by Hookes law: where k = the spring constant (N/m). The potential
energy stored in the spring U (J) can then be computed as

Five springs are tested and the following data compiled:


Table 1

Test 1 2 3 4 5

F (N) 14 18 8 9 13

x, (m) 0.13 0.20 0.09 0.10 0.12

a) Create a m-file to determine the spring constant in each test, the potential energy, and
the average value of potential energy.

i) The program should return the result as shown below

ii) The program should return the result as below


SKTK1533 Introduction to Computer Programming 20172018-1

b) Create a function file with input data of x and F and return the average value of
potential energy as output
c) Using the same function file in (2), return the potential energy and average value of
potential energy as output.

2. The density of freshwater can be computed as a function of temperature with the following
cubic equation:

where = density (g/cm3) and TC = temperature (C).

a) Write a program that can return the following output

b) Create a program that has output as given below

You might also like