Vous êtes sur la page 1sur 3

UNIVERSITY OF JORDAN COMPUTER ENGINEERING DEPARTMENT CPE0907311 COMPUTER APPLICATIONS LAB EXERCISE SHEET 4 STUDY THE SLIDES OF EXPERIMENT

4 AND SOLVE THE FOLLOWING PROBLEMS BEFORE COMING TO THE LAB.


1. The capacitance of two parallel conductors of length L and radius r, separated by a distance d

is given by

C=

L
dr ln r

where is the permittivity of air ( =8.854x10-12 F/m). Write a script file that accepts user input for C, L, and r, and computes and displays the distance value d that gives in the specified capacitance value C. Test your file with L = 0.5 m, r = 0.01 m, and C = 1 F.

Script File Code

The distance d is

2. Repeat Problem 1 by writing a Matlab function that accepts the input values C, r, and L in its

argument and returns calculated value d. Your function should be written such that it is capable of processing single and multiple values for C, r, and L, i.e. it should operate on vectors. Test your function with the following values C = [2 mF , 0.1 mF], L = [0.2 m 0.1m], and r = [0.05 and 0.02]. Function Code

1
PreparedbyDr.IyadJafar

UNIVERSITY OF JORDAN COMPUTER ENGINEERING DEPARTMENT CPE0907311 COMPUTER APPLICATIONS LAB EXERCISE SHEET 4

Distance
3. Use a text editor to create a file containing the data given below. Write a Matlab function that

accepts the name of the file as a string and returns the content of the file and the minimum and maximum values of each row in three output arguments: data,minValue, and maxValue. 23 , 33, 15, -9, -91, 14, 2, 3.3, 73, 5.43, 32, 1, 2 3 -21 11

Code

4. Enter and save the data given in problem 4 in a spreadsheet. Write a script file to import the

data to a MATLAB variable M then displays the sum of elements of the loaded data on the command prompt.

Script File Code

2
PreparedbyDr.IyadJafar

UNIVERSITY OF JORDAN COMPUTER ENGINEERING DEPARTMENT CPE0907311 COMPUTER APPLICATIONS LAB EXERCISE SHEET 4

Answer
5. Write a function to find the coefficients of the polynomial y = ax3 + bx2 + cx + d. The

functions should accept a set of four data points (xi,yi), i=1,2,3,4 and solve four linear equations in terms of the four unknowns a,b,c, and d. Test your function for the case where (xi,yi)= (-2,-20), (0,4), (2,68), and (4,508), whose answer is a = 7, b=5, c = -6, and d = 4.
6.

A company wants to locate a distribution center that will serve six of its major customers in a 30x30 mi area. The locations of the customers relative to the southwest corner of the area are given in the following table in terms of (x,y) coordinates (the x direction is east; the y direction is north) (see figure below). Also given is the volume in tons per week that must be delivered from the distribution center each customer. The weekly delivery cost ci for customer i depends on the volume Vi and distance di from the distribution center. For simplicity we will assume that the distance is a straight line distance. The weekly cost ci = 0.5 Vi * di ; i = 1,2,,6. Formulate the total cost function for all customers then use MATLAB to find the optimal location for the distribution center (the location that produces the minimum total weekly cost). Hint: formulate the objective function as a function handle and then use the fminsearch function. Customer 1 2 3 4 5 6
30

x Location (miles 1 7 8 17 22 27

y Location (miles) 28 18 16 2 10 8

Volume (tons/week) 3 7 4 5 2 6

1
25

20

2 3

y (miles)

15

5
10

10

15

20

25

30

x (miles)

3
PreparedbyDr.IyadJafar

Vous aimerez peut-être aussi