Você está na página 1de 5

Introduction to MATLAB

Practice Problems

Problem 1:
Calculate: 1. 23+73+2733/2 +553/2 2. cos(5/6) 2sin2 (7/8) + tan( ln8 ) 6 7 x 5/2

Problem 2:
1. Create a row vector that has elements : 1. 32, 4, 81, 63, cos(/3), 14.12 2. Create a column vector that has elements: 1. 55, 14, ln(51), 987,0 3. Create a row vector in which first element is 1, the last element is 33, with an increment of 2 between the elements (1,3,5,33) 4. Create a column vector in which first element is 15, the elements decreases with an increments of -5 and the last element is -25 (15, 10, 5-25

Problem 3:
1. Create a row vector called X whose elements are the integers 1through 9. 2. Create another row vector called Temp whose elements are: 15.6, 17.5, 36.6, 43.8, 58.2, 61.6, 64.2, 70.4, 98.8. 3. These data are the result of an experiment on heat conduction through an iron bar. The array X contains positions on the bar where temperature measurements were made. The array Temp contains the corresponding temperatures. 4. Make a 2-D plot with temperature on the y-axis and position on the x-axis. 5. The data shown in your plot should lie along a straight line (according to physics) but dont because of measurement errors. Use the MATLAB polyfit function to fit the best line to the data. In other words use polyfit to determine the coefficients a and b of the equation T=ax+b

Problem 4:
1. Find out the roots of a polynomial: a. x4 -x3 - 32x2 + 60x 2. Using linspace command create a vector x with 400 values b/w points -3 to 6 3. Use polyval command to evaluate polynomial at different value of x. 4. Plot .

Problem 5:
1. Write a MATLAB command that will generate a column vector called theta. theta should have values from 2 to 2 in steps of /100. 2. Generate a matrix F that contains values of the following functions in each column: 3. Column 1: cos() 4. Column 2: cos(2 )(1+sin( 2)) 5. Column 3: e-0.1| | 6. Evaluate each of the above functions for the values in the theta vector from above. 7. Plot each of the columns of F against theta. Overlay the three plots, using a different color for each. 8. Create a new column vector called maxVect that contains the largest of the three functions 9. Create a column vector called maxIndex that has the column number of maximum value in that row.

Problem 6:
1. Show views from various angles of the surface defined by the following function. z = |x| * exp(-x2-y2) * y in MATLAB, use: Z = abs(X) .* exp(-X .^ 2 Y .^ 2) .* Y; 2. Define an x-y grid with x and y in [-2, 2] with increments of 0.2. Show a total of 3views in the same figure. Camera parameters for each view should appear in the title for the sub-image. Detailed Instructions 1. Use meshgrid to define the grid ([X, Y]=meshgrid(-2:0.2:2, -2:0.2:2) 2. Use the dot operator for the multiplication and exponentiation 3. Use subplot to get multiple plots in the same figure 4. Use surfc for the three plots 5. Use the shading function to achieve desired appearance 6. Set the title for each view using the title function

Problem 7:
1. Create, perhaps using for-loops, a synthetic image that has a 1 in the (1,1) location, and a 255 in the (128,128) location, and i + j - 1 in the i, j location. This we'll refer to as the ``diagonal gray'' image. Can you manage to do this without using for-loops? 2. Display the image using (well assume you placed your image in a matrix named a) a. imagesc (a); b. colormap(gray); 3. Now convert your code to a MATLAB script 4. Test your script to insure that it produces the same results as interactively using the MATLAB command window.

Problem 8
A sample supported beam that is subjected to a constant distributed load w over half of its length is shown in the figure. The deflection y, as a function of x, is given by the equations: y= -wx (16x3 - 24Lx2 + 9L3) for 0 x L/2 384EI y= -wL (8x3 24Lx2 +17L2x L3 ) for L/2 x L 384 EI Where E= elastic mode, I=moment of inertia, L=Length of the beam
L/2 L/2

w
X

For the beam shown in the figure L=20m; E=200x109 Pa(steel); I= 348x10-6 m4 and w= 5x103 N/m. Make a plot of the deflection of the beam y as a function of x

Problem 9:
1. Write a MATLAB function that implements Newtons iterative algorithm for approximating the square root of a number. 2. The core of Newtons algorithm is that if last is the last approximation calculated the next (improved) approximation is given by next=0.5(last +(x/last)) 3. where x is the number you want the square root of 4. Two other pieces of information are needed to implement the algorithm. The first is an initial guess at the square root. (A typical starting value might be 1.0, say). The second is the accuracy required for the approximation. You might specify you want to keep iterating until you get an approximation that is good to 5 decimal places, for example. 5. Your MATLAB function should have three input arguments: x, the initial guess, and the accuracy desired. It should have one output, the approximate square root of x to the desired accuracy.

Problem 10:

m 0m 12

250m m

Piston-crank mechanism
The piston-connecting rod-crank mechanism is used in many engineering applications. In the mechanism shown in the following figure, the crank is rotating at a constant speed of 500 rpm. Calculate and plot the position, velocity, and acceleration of the piston for one revolution of the crank, Make the three plots on the same page. Set = 0 when t=0.

Você também pode gostar