Write a user-defined MATLAB function for the following math function: y(x) = (- 0.2x3 + 7x2)e-0.3x The input to the function is x and the output is y. Write the function such that x can be a vector (use element-by-element operations). (a) Use the function to calculate y(-1.5) and y(5). (b) Use thefunction to make a plot of thefunction y(x) for -2x6.
Read more- Math / MATLAB: An Introduction with Applications 5 / Chapter 7 / Problem 28
Table of Contents
Textbook Solutions for MATLAB: An Introduction with Applications
Question
Write a user-defmed function that fmds the largest element of a matrix. For thefunction name and arguments, use [Em, rc] = matrixmax (A), where A isany size matrix. The output argument Em is the value of the largest element,and rc is a two-element vector with the address of the largest element (rowand column numbers). If there are two, or more, elements that have the maximumvalue, the output argument rc is a two-column matrix where the rowslist the addresses of the elements. Test the function three times. For input createa 4 x 6 matrix using the following command: x=randi ( [- 2 0100] ,4,6)
Solution
The first step in solving 7 problem number 28 trying to solve the problem we have to refer to the textbook question: Write a user-defmed function that fmds the largest element of a matrix. For thefunction name and arguments, use [Em, rc] = matrixmax (A), where A isany size matrix. The output argument Em is the value of the largest element,and rc is a two-element vector with the address of the largest element (rowand column numbers). If there are two, or more, elements that have the maximumvalue, the output argument rc is a two-column matrix where the rowslist the addresses of the elements. Test the function three times. For input createa 4 x 6 matrix using the following command: x=randi ( [- 2 0100] ,4,6)
From the textbook chapter User-Defined Functions
and Function Files you will find a few key concepts needed to solve this.
Visible to paid subscribers only
Step 3 of 7)Visible to paid subscribers only
full solution
Write a user-defmed function that fmds the largest element of a matrix. For thefunction
Chapter 7 textbook questions
-
Chapter 7: Problem 1 MATLAB: An Introduction with Applications 5 -
Chapter 7: Problem 2 MATLAB: An Introduction with Applications 5Write a user-defined MATLAB function for the following math function: r(8) = 4cos(4sin8) The input to the function is e (in radians) and the output is r. Write the function such that e can be a vector. (a) Use the function to calculate r(n/6) and r(51C/6). (b) Use the function to plot (polar plot) r(8) for 0 e 2n.
Read more -
Chapter 7: Problem 3 MATLAB: An Introduction with Applications 5The fuel consumption of an airplane is measured in gal/mi (gallon per mile) or in L/lan (liter per kilometers). Write a MATLAB user-defined function that converts fuel efficiency consumption from gaVmi to L/lan. For the function name and arguments, use Lkm=LkmToGalm(gmi). The input argument gmi is the consumption in gaVmi, and the output argument Lkm is the consumption in L/km. Use the function in the Command Window to: (a) Determine the fuel consumption in L/lan of a Boeing 74 7 whose fuel consumption is about 5 gaVmi. (b) Determine the fuel consumption in L/km of the Concorde whose fuel consumption is about 5.8 gaVmi.
Read more -
Chapter 7: Problem 4 MATLAB: An Introduction with Applications 5Tables of materials properties list density, in units of kg/m3, when the international system of units (SI) is used and list specific weight, in units of lb/in3, when the U.S. customary system of units are used. Write a user-defmed MATLAB function that converts density to specific weight. For the function name and arguments, use [sw] = DenToSw (den). The input argument den is the density of a material in kg/m3, and the output argument sw is the specific weight in lb/in3. Use the function in the Command Window to: (a) Determine the specific weight of steel whose density is 7860 kg/m3 (b) Determine the specific weight of titanium whose density is 4730 kg/m3
Read more -
Chapter 7: Problem 5 MATLAB: An Introduction with Applications 5Write a user-defined MATLAB function that converts speed given in units of knots (one knot is one nautical mile per hour) to speed in units of feet per second. For the function name and arguments, use fps = ktsTOfps (kts). The input argument k t s is the speed in knots, and the output argument fp s is the speed in ft/s. Use the function to convert 400 kts to units offt/s.
Read more -
Chapter 7: Problem 6 MATLAB: An Introduction with Applications 5The body surface area (BSA) in m2 of a person (used for determining dosage of medications) can be calculated by the formula (DuBois formula): BSA = 0.007184fVl.425.ffl75 in which w is the mass in kg and His the height in em. Write a MATLAB user-defined function that calculates the body surface area. For the function name and arguments, use BSA = BodySurA (w, h). The input arguments w and h are the mass and height, respectively. The output argument BSA is the BSA value. Use the function to calculate the body surface area of: (a) A 95 kg, 1.87 m person. (b) A 61 kg, 1.58 m person.
Read more -
Chapter 7: Problem 7 MATLAB: An Introduction with Applications 5The fuel tank shown in the figure in shaped as a frustum of cone with r = 20 in., and H = 2r . Write a user-defined function (for the function name and arguments, use V = Volfuel (y)) that gives the volume of fuel in the tank (in gallons) as a function of the height y (measured from the bottom). Use the function to make a plot of the volume as a function of h for 0 h 40 in.
Read more -
Chapter 7: Problem 8 MATLAB: An Introduction with Applications 5The surface area S of a ring in shape of a torus with an inner radius r and a diameter d is given by: S = 1t2(2r + d)d The ring is to be plated with a thin layer of coating. The weight of the coating W can be calculated approximately as W = y S t , where y is the specific weight of the coating material and t is its thickness. Write an anonymous function that calculates the weight of the coating. The function should have four input arguments, r, d, t, and y. Use the anonymous function to calculate the weight of a gold coating ( y = 0.696 lb/in.3) of a ring with r = 0.35 in., d = 0.12 in., and t = 0.002 in.
Read more -
Chapter 7: Problem 9 MATLAB: An Introduction with Applications 5The windchill temperature T we is the perceived air temperature felt by the body on exposed skin due to the flow of air. For temperatures below 50F and wind speed higher than 3 mph, it is calculated by: T we = C1 + CzTA + C3 .16 + C4TA .16 where TA is the air temperature in degrees F, V is the wind speed in mph, C1 = 35.74 , C2 = 0.6215 , C3 = -35.75, and C4 = 0.4275. Write a userdefmed function for calculating T we for given TA and V. F or the function name and arguments, use Twc=WindChill (T 1 V). The input arguments are T the air temperature in oF and V the wind speed in mph, respectively. The output argument is Twc, the windchill temperature in oF (rounded to the nearest integer). Use the function to determine the windchill temperature for the following conditions: (a) T = 35 F, V = 26 mph. (b) T = 10 F, V = 50 mph.
Read more -
Chapter 7: Problem 10 MATLAB: An Introduction with Applications 5Write a user-defmed function that calculates grade point average (GPA) on a scale of 0 to 4, where A = 4, A-= 3.7 , B+ = 3.3 , B = 3, B- = 2.7 , C+ = 2.3 , C = 2, C- = 1.7 , D+ = 1.3 D = 1, and E = 0. For the function name and arguments, use av = GPA ( g 1 h). The input argument g is a vector whose elements are the numerical values of the grades. The input argument h is a vector with the corresponding credit hours. The output argument avis the calculated GPA. Use the function to calculate the GPA for a student with the following record:
Read more -
Chapter 7: Problem 11 MATLAB: An Introduction with Applications 5The factorial n! of a positive number (integer) is defmed by n! = n(n-1)(n-2 ). .. 321, where 0! = 1. Write a user-defined function that calculates the factorial n! of a number. For function name and arguments, use y=fact (x), where the input argument x is the number whose factorial is to be calculated and the output argument y is the value x! . The function displays an error message if a negative or non-integer number is entered when the function is called. Do not use MATLAB built-in function factorial. Use fact with the following numbers: (a) 9! (b) 8.5! (c) 0! (d) -5!
Read more -
Chapter 7: Problem 12 MATLAB: An Introduction with Applications 5Write a user-defmed MATLAB function that determines the angle that forms by the intersection of two lines. For the function name and arguments, use th=anglines (A,B,C). The input arguments to the function are vectors with the coordinates of the points A, B, and C, as shown in the figure, which can x be two- or three-dimensional. The output th is the angle in degrees. Use the function anglines for determining the angle for the following cases: (a) A(-5, -1, 6), B(2.5, 1.5, -3.5), C(-2.3, 8, 1) (b) A(-5.5, 0), B(3.5, -6.5), C(O, 7)
Read more -
Chapter 7: Problem 13 MATLAB: An Introduction with Applications 5Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two points (A and B) in space. For the function name and arguments, use n = uni tvec (A, B). The input to the function are two vectors A and B, each with the Cartesian coordinates of the corresponding point. The output is a vector with the components of the unit vector in the direction from A to B. If points A and B have two coordinates each (they are in the x y plane), then n is a two-element vector. If points A and B have three coordinate each (general points in space), then n is a three-element vector. Use the function to determine the following unit vectors: (a) In the direction from point (1.2, 3.5) to point (12, 15) (b) In the direction from point (-10, -4, 2.5) to point (-13, 6, -5)
Read more -
Chapter 7: Problem 14 MATLAB: An Introduction with Applications 5Write a user-defined MATLAB function that determines the cross product of two vectors. For the function name and arguments, use w=crosspro (u, v). The input arguments to the function are the two vectors, which can be two- or three-dimensional. The output w is the result (a vector). Use the function crosspro for determining the cross product of: (a) Vectors a = 3i + llj and b = 14i- 7.3} (b) Vectors c = - 6i + 14.2} + 3k and d = 6.3i- 8}- 5.6k
Read more -
Chapter 7: Problem 15 MATLAB: An Introduction with Applications 5The area of a triangle ABC can be calculated by: A= !IABxACI 2 where AB is the vector from point A to point B and AC is the vector from point A to point C. Write a user-defmed MATLAB function that determines the area of a triangle given its vertices' coordinates. For the function name and arguments, use [Area] = TriArea (A, B, C). The input arguments A, B, and C, are vectors, each with the coordinates of the corresponding vertex. Write the code ofTriArea such that it has two subfunctions---one that determines the vectors AB and AC and another that executes the cross product. (If available, use the user-defmed functions from Problem 14). The function should work for a triangle in the x-y plane (each vertex is defmed by two coordinates) or for a triangle in space (each vertex is defined by three coordinates). Use the function to determine the areas of triangles with the following vertices: (a) A = (1, 2), B = (10, 3), C = (6, 11) (b) A = (-1.5, -4.2, -3), B = (-5.1, 6.3, 2), C = (12.1, 0, -0.5)
Read more -
Chapter 7: Problem 16 MATLAB: An Introduction with Applications 5Write a user-defined MATLAB function that determines the circumference of a triangle when the coordinates of the vertices are given. For the function name and arguments, use [cr] = cirtriangle (A, B, C). The input arguments A, B, C are vectors with the coordinates of the vertices, and the output variable cr is the circumference. The function should work for a triangle in the x-y plane (each vertex is defmed by two coordinates) or for a triangle in space (each vertex is defmed by three coordinates). Write the code of cirtriangle such that it has a subfunction or an anonymous function for calculating the distance between two points. Use the function to determine the circumference of triangles with the following vertices: (a) A = (1, 2), B = (10, 3), C = (6, 11) (b) A = (-1.5, -4.2, -3), B = (-5.1, 6.3, 2), C = (12.1, 0, -0.5)
Read more -
Chapter 7: Problem 17 MATLAB: An Introduction with Applications 5Write a user-defmed function that plots a circle given the coordinates of the center and a point on the circle. For the function name and arguments, use circle PC ( c , p). The input argument c is a two-element vector with the x and y coordinates of the center and the input argument p is a two-element vector with the x and y coordinates of the a point on the circle. This function has no output arguments. Use the function to plot the following two circles (both in the same figure): (a) Center at x = 7.2 , y = -2.9, point on the circle at x = -1.8, y = 0.5 (b) Center at x = -0.9, y = -3.3, point on the circle at x = 0, y = 10
Read more -
Chapter 7: Problem 18 MATLAB: An Introduction with Applications 5Write a user-defined MATLAB function that converts integers written in decimal form to binary form. Name the function b=Bina (d) , where the input argument d is the integer to be converted and the output argument b is a vector with 1 s and Os that represents the number in binary form. The largest number that could be converted with the function should be a binary number with 16 1 s. If a larger number is entered as d, the function should display an error message. Use the function to convert the following numbers: (a) 100 (b) 1002 (c) 52,601 (c) 200,090
Read more -
Chapter 7: Problem 19 MATLAB: An Introduction with Applications 5Write a user-defmed function that plots a triangle and the circle that circumscribes the triangle, given the coordinates of its vertices. For the function name and arguments, use TriCirc (A, B, C). The input arguments are vectors with the x and y coordinates of the vertices, respectively. This function has no output arguments. Use the function with the points (1.5, 3), (9, 10.5), and (6, -3.8).
Read more -
Chapter 7: Problem 20 MATLAB: An Introduction with Applications 5Write a user-defined function that plots an ellipse y with axes that are parallel to the x and y axes, given the coordinates of its center and the length of the axes. For the function name and arguments, use ellipseplot (xc, yc, a, b). The input arguments xc and yc are the coordinates X of the center, and a and b are half the lengths of the horizontal and vertical axes (see figure), respectively. This function has no output arguments. Use the function to plot the following ellipses: (a) xc = 3.5, yc = 2.0, a = 8.5, b = 3 (b) xc = -5, yc = 1.5, a = 4, b = 8
Read more -
Chapter 7: Problem 21 MATLAB: An Introduction with Applications 5In polar coordinates a two-dimensional vector is y given by its radius and angle (r, e). Write a userdefmed MATLAB function that adds two vectors that are given in polar coordinates. For the function name and arguments, use [r th] = AddVecPol ( rl, thl, r2, th2), where the input arguments are (r1, e,) and X (r2, e2), and the output arguments are the radius and angle of the result. Use the function to carry out the following additions: (a) r1 = (5, 23) , r2 = (12, 40) (b) r1 = (6, 80), r2 = (15, 125)
Read more -
Chapter 7: Problem 22 MATLAB: An Introduction with Applications 5Write a user-defmed function that fmds all the prime numbers between two numbers m and n. Name the function pr=prime (m, n), where the input arguments m and n are positive integers and the output argument pr is a vector with the prime numbers. If m > n is entered when the function is called, 253 the error message "The value of n must be larger than the value of m." is displayed. If a negative number or a number that is not an integer is entered when the function is called, the error message "The input argument must be a positive integer." is displayed. Do not use MATLAB's built-in functions primes and i sprime. Use the function with: (a) prime(l2,80) (b) prime(21,63.5) (c) prime(l00,200) (d) prime(90,50)
Read more -
Chapter 7: Problem 23 MATLAB: An Introduction with Applications 5The geometric mean GM of a set of n positive numbers x1, x2, ... , xn is defined by: GM = ( xi. Xz . ... . xn ) lln Write a user-defined function that calculates the geometric mean of a set of numbers. For function name and arguments use GM=Geomean (x) , where the input argument xis a vector of numbers (any length) and the output argument GM is their geometric mean. The geometric mean is useful for calculating the average of rates. The following table gives the inflation rates in the United States from 1978 to 1987 (inflation of 7.6% means 1.076). Use the user-defmed function Geomean to calculate the average inflation for the tenyear period.
Read more -
Chapter 7: Problem 24 MATLAB: An Introduction with Applications 5Write a user-defined function that determines the polar y coordinates of a point from the Cartesian coordinates in a two-dimensional plane. For the function name and arguments, use [th rad] =CartToPolar (x, y). The input (II) arguments are the x andy coordinates of the point, and the output arguments are the angle e and the radial distance to (III) the point. The angle e is in degrees and is measured relative 1986 1987 1.019 1.036 (x, y) 8 (I) X (IV) to the positive x axis, such that it is a positive number in quadrants I and II, and a negative number in quadrant III and IV. Use the function to determine the polar coordinates of points (14, 9), (-11, -20), (-15, 4), and (13.5, -23.5).
Read more -
Chapter 7: Problem 25 MATLAB: An Introduction with Applications 5Write a user-defined function that determines the mode of a set of data (the value in the set that occurs most often). For the function name and arguments, use m=mostfrq (x). The input to the function is a vector x of any length with values, and the output m is a two-element vector in which the first element is the value in x that occurs most often, and the second element is the mode. If there are two, or more, values for the mode the output is the message: "There are more than one value for the mode." Do not use the MATLAB built-in function mode. Test the function three times. For input create a 20- element vector using the following command: x= rand i ( 1 0 , 1, 2 0 ) .
Read more -
Chapter 7: Problem 26 MATLAB: An Introduction with Applications 5Write a user-defined function that sorts the elements of a vector from the largest to the smallest. For the function name and arguments, use y=downsort (x). The input to the function is a vector x of any length, and the output y is a vector in which the elements of x are arranged in a descending order. Do not use the MATLAB built-in functions sort, max, or min. Test your function on a vector with 14 numbers (integers) randomly distributed between -30 and 30. Use the MATLAB randi function to generate the initial vector.
Read more -
Chapter 7: Problem 27 MATLAB: An Introduction with Applications 5Write a user-defined function that sorts the elements of a matrix. For the function name and arguments, use B = matrixsort (A), where A is any size (m x n) matrix and B is a matrix of the same size with the elements of A rearranged in descending order row after row with the (1,1) element the largest and the (m,n) element the smallest. If available, use the user-defmed function downsort from Problem 26 as a subfunction within matrixsort. Test your function on a 4 x 7 matrix with elements (integers) randomly distributed between -30 and 30. Use MATLAB's randi function to generate the initial matrix.
Read more -
Chapter 7: Problem 28 MATLAB: An Introduction with Applications 5Write a user-defmed function that fmds the largest element of a matrix. For the function name and arguments, use [Em, rc] = matrixmax (A), where A is any size matrix. The output argument Em is the value of the largest element, and rc is a two-element vector with the address of the largest element (row and column numbers). If there are two, or more, elements that have the maximum value, the output argument rc is a two-column matrix where the rows list the addresses of the elements. Test the function three times. For input create a 4 x 6 matrix using the following command: x=randi ( [- 2 0 100] ,4,6)
Read more -
Chapter 7: Problem 29 MATLAB: An Introduction with Applications 5Write a user-defmed MATLAB function that calculates the determinant of a 3 x 3 matrix by using the formula: det = Au I Azz Az3 1- A12 1 Azi Az3 1 + ABI Azi Azz l A32 A33 A31 A33 A31 A32 For the function name and arguments, use d3 = det3by3 (A), where the input argument A is the matrix and the output argument d3 is the value of the determinant. Write the code of det3by3 such that it has a subfunction that calculates the 2 x 2 determinant. Use det3by3 for calculating the determinants of: (a) [ l 7 8 J (b) [-25. 5 7 1 j
Read more -
Chapter 7: Problem 30 MATLAB: An Introduction with Applications 5A two-dimensional state of stress at a point in a loaded material in the direction defmed by the x-y coordinate system is defmed by three components of stress crxx' cryy, and 'txy The stresses at the point in the direction defmed by the x'- y' coordinate system are calculated by the stress transformation equations: cr +cr cr -cr cr , = xx YY + xx YY cos29 + 't sin29 X X 2 2 xy cr -cr 't , , = - xx YY sin29 + 't cos29 x y 2 xy cry'y' = crxx + O"yy-crx'x' where e is the angle shown in the figure. Write a userdefined MATLAB function that determines the stresses crx'x'' O"y'y'' and 'tx'y' given the stresses crxx' crYY, 'txy, and the angle e. For the function name and arguments, use [Stran] =StressTrans (S 1 th). The input argumentS is a vector with the values of the three stress components crxx crYY' and 'txy and the input argument this a scalar with the value of e. The output argument Stran is a vector with the values of the three stress components crx'x', cry'y', and 'tx'y'. Use the function to determine the stresses transformation for the following cases: (a) crxx = 160 MPa, cryy = -40 MPa, and 'txy = 60 MPa, e = 20 (b) crxx = -18ksi, cryy = 10ksi,and 'txy = -8ksi, 9 = 65.
Read more -
Chapter 7: Problem 31 MATLAB: An Introduction with Applications 5The dew point temperature Ta and the relative humidity RH can be calculated (approximately) from the dry-bulb T and wet-bulb Tw temperatures by (http:/ /www.wikipedia.org): e8 = 6.112exp ( 17.67T ) T+ 243_5 ( 17.67Tw ew = 6.112exp ) Tw + 243.5 e = ew-Psta(T-Tw)0.00066 (1+0.00115Tw) RH = 100. T = 243.5 ln(e/6.112) e8 d 17.67-ln(e/6.112) where the temperatures are in degrees Celsius, RH is in %, and Psta is the barometric pressure in units of millibars. Write a user-defmed MATLAB function that calculates the dew point temperature and relative humidity for given dry-bulb and wet-bulb temperatures in degrees Fahrenheit ( F) and barometric pressure in inches of mercury (inHg). For the function name and arguments, use [Td1 RH] = DewptRhum (T I Tw I BP), where the input arguments T I Tw I BP are dry-bulb and wet-bulb temperatures in oF and BP is the barometric pressure in inHg, respectively. The output arguments Td 1 RH are the dew point temperature in o F and the relative humidity in %. The values of the output arguments should be rounded to the nearest tenth. Use anonymous function or sub functions inside DewptRhum to convert units. Use the user-defined function DewptRhum for calculating the dew point temperature and relative humidity for the following cases: (a) T = 78 F, Tw = 66 F, Psta = 29.09 inHg (b) T = 97 o p, Tw = 88 op, Psta = 30. 12 mbar
Read more -
Chapter 7: Problem 32 MATLAB: An Introduction with Applications 5In a lottery the player has to select several numbers out of a list. Write a userdefmed function that generates a list of n integers that are uniformly distributed between the numbers a and b. All the selected numbers on the list must be different. For function name and arguments, use x=lotto (a, b, n) where the input argument are the numbers a andb, andn, respectively. The output argument x is a vector with the selected numbers. (a) Use the function to generate a list of seven numbers from the numbers 1 through 59. (b) Use the function to generate a list of eight numbers from the numbers 50 through 65. (c) Use the function to generate a list of nine numbers from the numbers -25 through-2.
Read more -
Chapter 7: Problem 33 MATLAB: An Introduction with Applications 5The Taylor's series expansion for cosx about x = 0 is given by: x2 x4 x6 (-1)n 2n COSX = 1-2!+4! -6!+ ... = &o ( 2n )! X where x is in radians. Write a user-defined function that determines cosx using Taylor's series expansion. For function name and arguments, use y=cosTay (x), where the input argument x is the angle in degrees and the output argument y is the value for cosx. Inside the user-defmed function, use a loop for adding the terms of the Taylor's series. If an is the nth term in the series, then the sum Sn of the n terms is Sn = Sn _1 +an. In each pass, calculate the estimated errorE given byE= I Sn-Sn-11. Stop adding terms when sn-1 E 0.000001. Since cos(e) = cos(e 360n) write the user-defined function such that if the angle is larger than 360, or smaller than -360 ,then the taylor series will be calculated using the smallest number of terms (using a value for x that is closest to 0). Use cosTay for calculating: (a) cos67 (b) cos200 (c) cos-80 . (d) cos794 (e) cos20000 .(j) cos-738 Compare the values calculated using cosTay with the values obtained by using MATLAB's built-in cosd function.
Read more -
Chapter 7: Problem 34 MATLAB: An Introduction with Applications 5Write a user-defmed function that determines the 1------r' --------.j l coordinate y c of the centroid of the U -shaped cross-sectional area shown in the figure. For the T i d function name and arguments, use yc = cen- h- - troidU (w 1 h1 t 1 d), where the input argu- l ments w, h, t, and d, are the dimensions shown . - -1'c r-- T I Yc I I - in the figure and the output argument yc is the --1 1 !- coordinate y c Use the function to determine Yc for an area with w = 10 in., h = 7 in., d = 1.75 in., and t = 0.5 in.
Read more -
Chapter 7: Problem 35 MATLAB: An Introduction with Applications 5The area moment of inertia Io of a rectangle about the axis X0 passing through its centroid is Ixo = 1;bh 3 The moment of inertia about an axis x that is parallel to x0 is given by Ix = Ixo +Ad; , where A is the area of the rectangle, and dx is the distance between the two axes. Write a MATLAB user-defined function that 1------- r' --------.j l determines the area moment of inertia Ixc of a T i d "U" beam about the axis that passes through its --'c r-f-T centroid (see drawing). For the function name h 1 Yc and arguments use Ixc=IxcT- l 1 Beam (w I hit I d), where the input arguments w, --1--; 1--- 1 . h, t, and dare the dimensions shown in the figure and the output argument Ixc is Ixc. For fmding the coordinate y c of the of the centroid, use the user-defmed function centroidU from Problem 34 as a subfunction inside IxcUBeam. (The moment of inertia of a composite area is obtained by dividing the area into parts and adding the moments of inertia of the parts.) Use the function to determine the moment of inertia of a "U" beam w = 12 in., h = 8 in., d = 2 in., and t = 0.75 in.
Read more -
Chapter 7: Problem 36 MATLAB: An Introduction with Applications 5In a low-pass RL filter (a filter that passes signals with low frequencies), the ratio of the magnitudes of the voltages is given by: where ro is the frequency of the input signal. L R Write a user-defmed MATLAB function that calculates the magnitude ratio. For the function name and arguments, use RV = LRFil t (R, L, w). The input arguments are R, the size of the resistor inn (ohms); L, the size of the capacitor in H (Henry); and w, the frequency of the input signal in rad/s. Write the function such that w can be a vector. Write a program in a script file that uses the LRF i l t function to generate a plot of RV as a function of co for 10::;; w::;; 106 rad/s. The plot has a logarithmic scale on the horizontal axis (co). When the script file is executed, it asks the user to enter the values of R and L. Label the axes of the plot. Run the script file with R = 600 Q, and L = 0.14 -
Read more -
Chapter 7: Problem 37 MATLAB: An Introduction with Applications 5A circuit that filters out a certain frequency is shown in the figure. In this filter, the ratio of the magnitudes of the voltages is given by: RV= IV01 = IR(1-w2LC)I V; J(R-Rw2LC)2+(wL)2 where co is the frequency of the input signal. L V; R Write a user-defined MATLAB function that calculates the magnitude ratio. For the function name and arguments, use RV = f i l tf req ( R, c, L , w). The input arguments are R the size of the resistor in n (ohms); C, the size of the capacitor in F (farads); L, the inductance of the coil in H (henrys); and w, the frequency of the input signal in rad/s. Write the function such that w can be a vector. Write a program in a script file that uses the f i l t f req function to generate a plot with two graphs of RVas a function of co for 10::;; w::;; 104 rad/s. In one graph C = 160 . L = 45 mH, and R = 200 n, and in the second graph C and L are the same and R = 50 Q The plot has a logarithmic scale on the horizontal axis (co). Label the axes and display a legend.
Read more -
Chapter 7: Problem 38 MATLAB: An Introduction with Applications 5The first derivative d) of a function f(x) at a point x = x0 can be approximated with the two-point central difference formula: df(x) = f(x0+h)-f(x0-h) dx 2h where h is a small number relative to x0 Write a user-defmed function function (see Section 7.9) that calculates the derivative of a math function f(x) by using the two-point central difference formula. For the user-defined function name, use dfdx=Funder (Fun, xO), where Fun is a name for the function that is passed into Funder, and xO is the point where the derivative is calculated. Use h = x0/100 in the two-point central difference formula. Use the user-defmed function Funder to calculate the following: (a) The derivative of f(x) = x3 e2x at x0 = 0.6 (b) The derivative of f(x) = 3: at x0 = 2.5 X In both cases compare the answer obtained from Funder with the analytical solution (use format long).
Read more -
Chapter 7: Problem 39 MATLAB: An Introduction with Applications 5The new coordinates (X,, Y,) of a point in the x-y plane that is rotated about the z axis at an angle e (positive is clockwise) are given by X, = X0cos9- Y0sin9 Y, = X0sin9 + Y0cos9 where (X0, Y0) are the coordinates of the point before the rotation. Write a user-defined function that calculates (X7, Y7) given (X0, Y0) and e. For function name and arguments, use [xr I yr] =rotation (xl y I q), where the input arguments are the initial coordinates and the rotation angle in degrees and the output arguments are the new coordinates. (a) Use rotation to determine the new coordinates of a point originally at (6.5, 2.1) that is rotated about the z-axis by 25. (b) Consider the function y = (x -7)2 + 1.5 for 5 :5: x :5: 9. Write a program in a script file that makes a plot of the function. Then use rotation to rotate all the points that make up the first plot and make a plot of the rotated function. Make both plots in the same figure and set the range of both axes at 0 to 10.
Read more -
Chapter 7: Problem 40 MATLAB: An Introduction with Applications 5In lottery the player has to guess correctly r numbers that are drawn out of n numbers. The probability, P, of guessing m numbers out of the r numbers can be calculated by the expression: p c c = r,m (n-r),(r-m) cn,r where Cx,y = '( x )' . Write a user-defmed MATLAB function that calcuy. X y . lates P. For the function name and arguments, use P = ProbLottery (m1 r 1 n). The input arguments are m the number of correct guesses; r, the number of numbers that need to be guessed; and n, the number of numbers available. Use a subfunction inside ProbLottery for calculating Cx,y. (a) Use ProbLot tery for calculating the probability of correctly selecting 3 of 6 the numbers that are drawn out of 49 numbers in a lottery game. (b) Consider a lottery game in which 6 numbers are drawn out of 49 numbers. Write a program in a script file that displays a table with seven raws and two columns. The first column has the numbers 0, 1, 2, 3, 4, 5, and 6, which are the number of numbers guessed correctly. The second column show the corresponding probability of making the guess.
Read more