You are on page 1of 6

# LABORATORY BRIEF SHEET 1 PROGRAMMING WITH MATLAB (ECS2013)

LEARNING OUTCOME: Identify MATLAB computing language structure Identify methods of handling structure

GRADING CRITERIA: A B+ B C : 80% to 100% marks : 70% to 79% marks : 60% to 69% marks : 50% to 59% marks

ADVICE ON SOURCES OF INFORMATION: An Engineers Guide to MATLAB by Magrab ,Walsh. Matlab Programming for Engineers by Stephen Chapman, Intl Student Edition 2004 Programming in Matlab by Marc Herniter, 2000

## DURATION: Four weeks

Experiment 1 Write a Matlab script file to plot a sinusoidal waveform from -360 degrees to 360 degrees. (4 marks) Experiment 2 Using Matlab, create a sphere with center at the origin (0,0,0) using (n+1)2 points. (4 marks) Experiment 3 The volume of a circular cylinder of height h and radius r is given by V = r 2 h . A particular cylindrical tank is 15 meters tall and has a radius of 8 meters. We want to construct tank with a volume 20 percent greater but having the same height. How large must its radius be? (4 marks) Experiment 4 The arrays temp_A and temp_B given in the table contain the water temperature in degrees Fahrenheit of two points measured at noon for 10 days. Determine how many days the temperature of pond A was above 60o. On what days did it occur? Determine the temperature of pond A on the days when it was greater than or equal to the temperature of pond B. (4 marks) Experiment 5 1. A train is heading east at 60 miles per hour. A car approaches the track crossing at 45 miles per hour on a road that makes a 55o angle with the track. What is the velocity of the train relative to the car? What is the speed of the train relative to the car? (4 marks) 2. Suppose two divers start at the surface and establish the following coordinate system: x is to the west, y is to the north, and z is down. Diver 1 swims 55 feet west, 36 feet north, and then dives 25 feet. Diver 2 dives 15 feet, then swims east 20 feet and then north 59 feet. a) Find the distance between diver 1 and the starting point. b) How far in each direction must diver 1 swim to reach diver 2? How far in a straight line must diver 1 swim to reach to diver 2? (4 marks)

Experiment 6

The current i passing through an electrical resistor having a voltage V across it is given by Ohms law: i =V/R, where R is the resistance. The power dissipated in the resistor is given by V2/R. The following table gives the data for the resistance and voltage for five resistors. Use the data to compute R(ohms) V(volts) 1 104 120 2 2 x 104 80 3 3.5 x 104 110 4 105 200 5 2 x 105 350

a) the current in each resistor and b) the power dissipated in each resistor. (4 marks) Experiment 7

V1

Figure 1 Simple electrical circuit Figure 1 is a representation of an electrical system with a power supply and a load. The power supply produces the fixed voltage v1 and supplies the current i1 required by the load, whose voltage drop is v2. For 0<v2<20, the current voltage relationship for a specific load is found from experiments to be

i = 0.16(e 0.12V2 1)
Using Kirchoffs voltage law, we obtain: V1 i1 R1 V2 = 0

equation (1)

equation (2)

a) Suppose R1 = 40 and V1 =15V, plot v2 vs. i and i1 in the same axis. (Choose appropriate interval for v2 to give a smooth curve. (6 marks)

b) The plot of equation (1) is the device curve and the plot of equation (2) is a straight line called the load line. The load line is so named because it shows how the current drawn by the load changes as the loads voltage changes. Properly label the graph. (3 marks) Experiment 8 Perform the following basic command line exercises: 1. Evaluate the following expressions where u = 1 and v = 3: 4u 3v 2v 2 b) (u + v ) 2 a) v3 v3 u3 4 2 d) v 3 c) (3 marks) 2. Do the following tasks below. a) b) c) d) e) f) Create a vector of even numbers from 12 to 24. Add 4 for each element. Compute the square root of each element. Raise to the power of 4 each element from the vector calculated from 1.b). Present your answers from 1.a) to 1.b) in table form. Answers should be in two decimal places only. (3 marks)

3. Given a vector, t, of length n, write down the MATLAB expressions that will correctly compute the following: a. b. c. d. e. f. ln(2 + t + t2) et(1 + cos(3t)) cos2(t) + sin2(t) tan-1(1) (this is the inverse tangent function) cot(t) sec2(t) + cot(t) - 1 (4 marks) Experiment 9

Test that your solution works for 0<t<2 with 0.2 interval.

## Perform the following basic array syntax and manipulations: 1.

Figure 1 In the circuit shown above, the simultaneous equations generated using Kirchoffs voltage law are as follows: 300 I 1 + 100 I 2 + 150 I 3 = 0 100 I 1 + 650 I 2 300 I 3 = 0 150 I 1 + 300 I 2 450 I 3 = 24 Determine the values of I1, I2 and I3 using matrix operation. (3 marks) 2. Given the matrix A = [ 2 4 1 ; 6 7 2 ; 3 5 9], provide the commands needed to a. assign the first row of A to a vector called x1 b. assign the last 2 rows of A to an array called y c. compute the sum over the columns of A d. compute the sum over the rows of A e. compute the standard error of the mean of each column of A (Note: the standard error of the mean is defined as the standard deviation divided by the square root of the number of elements used to compute the mean.) (3 marks)

3. Given the array A from problem 2 above, provide the command that will

a. assign the even-numbered columns of A to an array called B b. assign the odd-numbered rows to an array called C c. convert A into a 4-by-3 array d. compute the reciprocal of each element of A e. compute the square-root of each element of A (3 marks) Experiment 10 Perform the following relational/logical exercises: Create the vector x = randperm(35) and then evaluate the following function using only logical indexing: y (x) = 2 if x < 6 = x 4 if 6 <= x < 20 = 36 x if 20 <= x <= 35 Check your answer by plotting y vs. x with symbols. The curve should be a triangular shape, always above zero and with a maximum of 16. (4 marks)