UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN COMP CO MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT CPE0907311 COMPUTER APPLICATIONS LAB CPE0907311 COMPUTER APPLICATIONS LAB EXERC EXERCISE SHEET 4 SE SHEET 4 STUD STUDY THE S Y THE SLIDES O IDES OF EXPERI EXPERIMENT 4 MENT 4 AND SOLV AND SOLVE THE FO E THE FOLLOW LLOWING ING PROB PROBLEMS LEMS BEFORE COMING TO THE LAB. BEFORE COMING TO THE LAB. 1. 1. The capacitance of two parallel conductors of length L and radius r, separated by a distance d is given by πε L C = − ⎛ ⎞ d r ⎜ ⎟ 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. 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 1 Prepared by Dr. Iyad Jafar
UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN COMP CO MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT CPE0907311 COMPUTER CPE0907311 COMPUTER APPLICATIONS LAB APPLICATIONS LAB EXERCISE SHEET 4 EXERC SE SHEET 4 Distance 3. Use a text editor to create a file containing the data given below. Write a Matlab function that 3. 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 , -91, 73, 2 33, 14, 5.43, 3 15, 2, 32, -21 -9, 3.3, 1, 11 Code 4. 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 2 Prepared by Dr. Iyad Jafar
UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN COMP CO MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT CPE0907311 COMPUTER CPE0907311 COMPUTER APPLICATIONS LAB APPLICATIONS LAB EXERCISE SHEET 4 EXERC SE SHEET 4 Answer 5. Write a function to find the coefficients of the polynomial y = ax 3 + bx 2 + cx + d. The 5. functions should accept a set of four data points (x i ,y i ), 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 (x i ,y i )= (-2,-20), (0,4), (2,68), and (4,508), whose answer is a = 7, b=5, c = -6, and d = 4. 6. 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 c i for customer i depends on the volume V i and distance d i from the distribution center. For simplicity we will assume that the distance is a straight line distance. The weekly cost c i = 0.5 V i * d i ; 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. x Location y Location Volume Customer (miles (miles) (tons/week) 1 1 28 3 2 7 18 7 3 8 16 4 4 17 2 5 5 22 10 2 6 27 8 6 30 1 25 2 20 y (miles) 3 15 5 6 10 5 4 0 0 5 10 15 20 25 30 x (miles) 3 3 Prepared by Dr. Iyad Jafar
Recommend
More recommend