ENGR 1371 – Computing for Engineers Engineering Studies Program
Transcription
ENGR 1371 – Computing for Engineers Engineering Studies Program
ENGR 1371 – Computing for Engineers Engineering Studies Program Armstrong Atlantic State University Projects Do the following problems. Please check this document regularly as it will be periodically updated. Most recently updated on 11-13-14. To receive full credit: • Please follow the instructions given with each problem. • All MATLAB programs must be submitted in accordance with the ‘Programming Assignment Format’. • All calculations and other work done using paper and pencil (as applicable) must be submitted in accordance with the ‘Engineering Problem Solving Format’. • All projects are due on the date due, class time (unless specified otherwise). • Do not use user-inputs (commands such as input) in any of the programs unless specified otherwise. Use relevant and well-defined variables that can be changed easily by the user so as to test your programs for different cases. Date Due Projects / Problems / Topics (continued on following pages) 11-20-14 Project # 12: Images Total points: 20 DO NOT use any built in functions from MATLAB’s image processing toolbox for these problems. 1. (10 points) Write a MATLAB program which does the following: Reads 3-5 images Creates a collage with the images in a format other than along one row or one column. Creates a border around the images (use a varied border width or color scheme). Displays the original images and the final collage as an image (in separate figure windows) Writes a new image file ‘collage.jpg’. Select images which are of similar size, format and relevant to engineering. You will be graded for creativity as well as your programming skills. Submit your image files along with your programs. Your program should work for any set of images (similar size and format). 2. (10 points) Write two MATLAB functions as specified below for image processing: • Write a function colorrgbtobrg.m which converts an RGB image to an image with colors set as BRG (colored layers are interchanged). Page 1 of 8 Instructor: Dr. Priya Goeser ENGR 1371 – Computing for Engineers Engineering Studies Program Armstrong Atlantic State University • • • • • Use the function syntax as: function outimage = colorrgbtobrg(inimage) Write a function image_reverse.m which reverses the image in order to ‘read’ the image from right to left (mirror image). Use the function syntax as: function outimage = image_reverse(inimage) Test your functions for several images, but you do not need to write or submit a test file. The instructor will test your functions using a test file similar to the one shown below: % read the original image and 'plot' it [origimage,origmap] = imread('sciencecenter.jpg'); figure image(origimage); axis off % process/change image and 'plot' the new image newimage = image_reverse(origimage); figure image(newimage); axis off 11-13-14 Project # 11: Interpolation, Curvefitting, Integration and Differentiation Total points: 20 Download relevant Excel file engr1371numericalmethods.xlsx from the class website and use it to read relevant data. Submit all relevant files including any input and output excel data files. 1. (5 points) The science of thermodynamics makes extensive use of tables when systems such as a power plant are analyzed. Depending on the system of interest you may need only a portion of the table, such as the following: Temperature C 100 150 200 Page 2 of 8 Specific Volume M3/kg 1.6958 1.9364 2.172 Internal Energy kJ/kG 2506.7 2582.8 2658.8 Enthalpy kJ/kg 2676.2 2776.4 2875.3 Instructor: Dr. Priya Goeser ENGR 1371 – Computing for Engineers Engineering Studies Program Armstrong Atlantic State University 250 300 400 500 2.406 2.639 3.103 3.565 2733.7 2810.4 2967.9 3131.6 2974.3 3074.3 3278.2 3488.1 Notice that this table is spaced at 50 degree intervals at first, and then at 100 degree intervals. Assume that you have a project that requires you to use this table, and you would prefer not to have to perform a linear interpolation every time you use it. • • • • Write a MATLAB program to create a table, applying linear interpolation, with a temperature spacing of 25 degrees. Read from engr1371numericalmethods.xlsx worksheet thermotables. Write the table (the output from the MATLAB program) into an Excel file: newtable.xls. Include the ‘txt’ as a header in your new excel file. 2. (10 points) Read from engr1371numericalmethods.xlsx worksheet rocketstagedata. a. (2 points) Write a MATLAB program to read the data (numeric and text) from the excel spreadsheet. • The columns of text represent the stages of the rocket. • The first column of numbers represents time in seconds. • The second column of numbers represents the altitude in meters. b. (5 points) Using the same MATLAB program, i. Create a variable t with the time data and a variable h for the altitude data. ii. Find the best-fit cubic curve (3rd order polynomial) for the above data. iii. Plot the raw data: time t on the x-axis and altitude h on the y-axis using ‘o’ markers. iv. On the same graph, plot the best-fit cubic curve using a solid red line. v. Include grid lines on your graph. vi. Include relevant labels with units on the graph. vii. Include a clearly labeled legend on the graph. c. (3 points) Using the same MATLAB program • • Page 3 of 8 dh ∆h for each stage of the rocket. ≅ ∆t dt Calculate the average velocity for each stage of the rocket using the above sets of v. Calculate the velocity using numerical differentiation v = Instructor: Dr. Priya Goeser ENGR 1371 – Computing for Engineers Engineering Studies Program Armstrong Atlantic State University • Your program should display the average velocities for each stage with relevant units (m/s) using the fprintf command. Write your program such that it works for any number of data for any three-stage rocket. 3. (5 points) The velocity (in m/s) as a function of time (in s) of a particle that moves along a straight line, is given as: for 0 ≤ t ≤ 10 s 1.4t 14 + 5 sin π (t − 10) for 10 ≤ t ≤ 25 s 10 v(t ) = for 25 ≤ t ≤ 35 s 9 9 for 35 ≤ t ≤ 40 s 9 − (t − 35) 5 Write a MATLAB program • To calculate velocity as a function of time from 0 to 40 seconds. • Use a time interval of 0.1 seconds. • Calculate the distance traveled during this time: d = ∫ vdt using numerical integration (trapezoidal rule). • • • Page 4 of 8 Using subplot o Plot the above velocity Vs time. o Plot the above distance vs. time. o Include relevant labels with units. Your program should also display as the output the total distance traveled with relevant units using the fprintf command. Do NOT use iteration for this problem. Instructor: Dr. Priya Goeser ENGR 1371 – Computing for Engineers Engineering Studies Program Armstrong Atlantic State University 10-30-14 Project # 10: Linear Algebraic Equations Total points: 20 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1. (10 points) Idealized spring mass systems have numerous applications in engineering. The figure shows an arrangement of 4 springs in series being compressed with a mass of m=1500 kg. At equilibrium, force balance equations can be developed defining the displacements in the springs: k 2 ( x 2 − x1 ) = k1 x1 k 3 ( x3 − x 2 ) = k 2 ( x 2 − x1 ) k 4 ( x 4 − x3 ) = k 3 ( x 3 − x 2 ) F = k 4 ( x 4 − x3 ) Where the k’s are spring constants. If k1 through k4 are 100, 50, 80 and 200 N/m respectively, compute x1 through x4. Note: F = mg where g =9.81 m/s2. • Write a MATLAB program to solve this problem. • You will need to re-write the 4 equations above using paper and pencil to bring it to the format Ax=b. o Include these equations as comments in your program OR neatly write them using pencil on your hard copy of the program. o Vector x should contain all unknowns: x1 through x4 o Vector b should contain the external force for this system: F o Matrix A should the coefficients in terms of the spring constants: k1 through k4 o Do not solve for the unknowns using algebraic manipulation • Clearly define A & b in the MATLAB program (use variables names such as m, g, k1, k2, etc.) • Solve for x using Gauss Elimination method (x=A\b). • Clearly show your output(s) including relevant units using the fprintf command. 2. (10 points) A juice company manufactures one-gallon bottles of three types of juice blends using orange, pineapple and mango juice. The blends have the following compositions: 1 gallon orange blend – 3 quarts of orange juice, 0.75 quart of pineapple juice, 0.25 quart of mango juice 1 gallon pineapple blend – 1 quart of orange juice, 2.5 quarts of pineapple juice, 0.5 quart of mango juice 1 gallon mango blend – 0.5 quarts of orange juice, 0.5 quart of pineapple juice, 3 quarts of mango juice Page 5 of 8 Instructor: Dr. Priya Goeser ENGR 1371 – Computing for Engineers Engineering Studies Program Armstrong Atlantic State University How many gallons of each blend can be manufactured if 7600 gallons of orange juice, 4900 gallons of pineapple juice and 3500 gallons of mango juice are available? • • • • • • Write a MATLAB program to solve this problem. You will need to re-write the above equations using paper and pencil to bring it to the format Ax=b. Include these equations as comments in your program OR neatly write them using pencil on your hard copy of the program. Write the equations in the format Ax=b. Clearly define A & b in the MATLAB program. Solve for x using the Gauss Elimination method. Clearly show your output(s) including relevant units using the fprintf command. 3. Take your solution (soft and hard copies of the program(s)) from Problem 1 and/or Problem 2 to the Engineering Studies tutoring center and have one of the ENGR 1371 tutors look over the overall solution process. Clearly show them using your hard copy with the equations used to create the A matrix and b vector. Please ensure that you sign in (include date and time) when you visit the tutors as this part will contribute towards your overall grade for the project. 10-23-14 Project # 9: Plotting Total points: 20 1. (10 points) Write a function displacementvelocity.m that takes as inputs - the parameters: v0 , a, t ; calculates the final velocity 1 using the equation of motion: v = v0 + at ; calculates the displacement using the equation of motion: d = v0t + at 2 ; and gives 2 the outputs as d and v. 2 Write a program to test your function displacementvelocity.m for the problem: v0 = 0 m / s , a = 9.81m / s and t = 0, 2, 4, 6, K 50 s . The program should call the above function to calculate the displacements and velocities. Include in the same program commands to plot two graphs on the same figure window (2 rows 1 column) representing: velocity vs time and displacement vs time with time on the x-axis. Include units as relevant for the axes. Do not use iteration. 2. (10 points) Three sides (x=0, y=0 and x=a) of a rectangular plate (a=5 m and b=4 m) are kept at a temperature of 0 C and one side y=b is kept at T0=80 C. Write a MATLAB program to compute and plot (a surface or mesh plot) the temperature Page 6 of 8 Instructor: Dr. Priya Goeser ENGR 1371 – Computing for Engineers Engineering Studies Program Armstrong Atlantic State University distribution T in the plate which is given as: πx πy sin (2n − 1) sinh (2n − 1) N 4T a a T ( x, y ) = 0 ∑ (2n − 1) sinh (2n − 1) πb π n =1 a where N is the number of terms in the above series, evaluated at each coordinate (x,y). • • • • • • 10-16-14 Assume N=100 for your computations. Assume an increment of 0.1 m along the x vector Assume an increment of 0.1 m along the y vector Clearly label all relevant axis including units. Include grid lines on your figure. Hint: Use a for loop to compute the sum of the terms. Project # 8: Cell Arrays, Structures & File I/O Total points: 20 Please review the tutorial on xlsread (application of cell array and used in Project 8): http://engineering.armstrong.edu/matlabmarina/fileio.html 4. (20 points) Write a function makematerial.m to create a structure with the object - material and fieldnames as defined below: • type – the material type as a string • name – the name given to the material as a string • yieldstrength – the yield strength as a number (include units as comments) • tensilestrength – the tensile strength as a number (include units as comments) • elongation – the percent elongation as a number (include units as comments) Go to the class website: http://engineering.armstrong.edu/priya/ENGR1371/ENGR1371.html and download the Excel file engr1371materials.xls from the lecture notes folder. Write a MATLAB program to do the following Read the data (numeric and text) from the excel spreadsheet. Do not copy and paste data. Use MATLAB command xlsread. Use the function makematerial.m to create a structure array with the information (material type, material name, yield Page 7 of 8 Instructor: Dr. Priya Goeser ENGR 1371 – Computing for Engineers Engineering Studies Program Armstrong Atlantic State University strength, tensile strength and percent elongation) of all the given materials. You may have to use a loop to create the above structure array. The first row/line read from the excel document is a header and can be ignored/deleted (from the data as read and not in the excel file itself) Take your program and function (completed up to this point) to the Engineering Studies tutoring center and have one of the ENGR 1371 tutors look over the programming style and/or the overall algorithm. Please ensure that you sign in (include date and time) when you visit the tutors as this part will contribute towards your overall grade for the project. Add the following to the same MATLAB program: Include in the MATLAB program commands to find the material with the maximum yield strength. Include in the MATLAB program commands to find the material with the maximum tensile strength. Include in the MATLAB program commands to find the material with the maximum percent elongation. Use fprintf to show the outputs - all information (material type, material name, yield strength, tensile strength and percent elongation) for each of the above three materials including relevant units. Your program should work for any number of materials. Your program should work with the original excel file (the instructor will test it with this file). FYI - The data in the excel document represents material properties of different materials. The ‘NaN’ represents data that is not applicable to that material. Page 8 of 8 Instructor: Dr. Priya Goeser