matlab assignments

12
MAE 294: Homework #1 Instructor: Mark Miner Assigned January 9, 2013 Due 12:00pm, January 11, 2013 I suggest you try these in MATLAB. In homework assignments as in your code, problems proceed sequentially and may call for a previously defined variable. Deliverables: Answers to the following questions. Submit via Blackboard, either in the response box or by attaching a file containing your answers. Problem 1 Variables 1.1 (5pts) Are the Following Variable Names Valid? (T/F) 1) IsBad VarName 2) 2CoolForSchool 3) IsBad?VarName 4) or 5) fourier 6) elif 7) sqrt 8) break 9) yourself 10) else 1.2 (2pts) Are Variable Names a and b Equivalent? (T/F) 1) a: sub 1 b: sub l 2) a: PapaJohn b: papajohn 1.3 (3pts) How Big Are These Variables? (row, column) 1) A = [1, 2, 3; 4, 5, 6] 2) b = [1, 2; 3, 4; 5, 6] 3) c = [123; 456] 4) d = [1; 2; 3; 4; 5; 6] 5) E =[A; A] 6) F =[A, c]

Upload: nilima

Post on 08-Sep-2015

219 views

Category:

Documents


4 download

DESCRIPTION

math

TRANSCRIPT

  • MAE 294: Homework #1Instructor: Mark Miner

    Assigned January 9, 2013Due 12:00pm, January 11, 2013

    I suggest you try these in MATLAB. In homework assignments as in your code,problems proceed sequentially and may call for a previously dened variable.

    Deliverables: Answers to the following questions. Submit via Blackboard, eitherin the response box or by attaching a le containing your answers.

    Problem 1 Variables

    1.1 (5pts) Are the Following Variable Names Valid? (T/F)

    1) IsBad VarName2) 2CoolForSchool3) IsBad?VarName4) or5) fourier6) elif7) sqrt8) break9) yourself10) else

    1.2 (2pts) Are Variable Names a and b Equivalent? (T/F)

    1) a: sub 1 b: sub l2) a: PapaJohn b: papajohn

    1.3 (3pts) How Big Are These Variables? (row, column)

    1) A = [1, 2, 3; 4, 5, 6]2) b = [1, 2; 3, 4; 5, 6]3) c = [123; 456]4) d = [1; 2; 3; 4; 5; 6]5) E = [A;A]6) F = [A, c]

  • MAE 294: Homework #2

    Instructor: Mark MinerAssigned January 11, 2013

    Due January 16, 2012

    Deliverables: Responses to the following questions, submitted via BlackBoard.

    Problem 1 (2pts) Numbers

    Given the following IEEE-754-dened values (in base-10, dont worry), tell me whatnumber is constructed:a)s=1, m=31416, b=10, e=-4b)s=0, m=64, b=2, e=-6

    Problem 2 Logicals

    2.1 (1pt) Logical variables appear in the Workspace windowas a:

    a) Checkboxb) Cubec) Square with lower case ab in itd) Doubly-bisected square

    2.2 (3pts) Given R=0, S=0, T=1, evaluate the following (1/0for true/false):

    a) R & Tb) S | Tc) S >= Td) (R & S) < Te) R =Tf) R == S

    Problem 3 (6pts) Arrays

    Given A=[ 16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1], nd the following:a) max(min(A,[],2))b) min(max(A,[],2))c) mean(max(A,[],1))d) max(mean(A,1))e) max(sum(A))f) sum(max(A))

  • MAE 215: Homework #3

    Instructor: Mark MinerAssigned January 16, 2013

    Due 11:59am, January 18, 2013

    Deliverables: Responses to the following questions.Optional Deliverables: A functioning MATLAB script which prints the responses.

    For each of the following questions, indicate how you obtained your answer (MAT-LAB, calculator, etc.). You may submit a script which performs the calculations (Iguarantee this is the easiest way to do them), though if you do, comment your codeso I can follow the logic. Submit functioning, commented, M-files named as follows:myASURITE hw3.m, for example, mjminer hw3.m

    Problem 1 Polynomial Roots

    Given the polynomial:y = 0.01x5 0.20x4 + 0.1x3 x + 10

    1.1 (3pts) Real Roots

    Solve for the three real roots.

    1.2 (2pts) Imaginary Roots

    Solve for the two imaginary roots (note that they are a pair of complex conjugates).

    . . . . . . . . .

    Problem 2 (10pts) Triangles

    Consider a generic right triangle abc :

    a

    b

    HHHHHHHH

    c

    Given the information in Table 1, calculate the area, perimeter, and lengths ofsides b and c of each of the triangles.

    Triangle Side a (m) Angle ac (Degrees)

    1 1 30

    2 1 50

    3 2 20

    4 3 45

    5 5 60

    . . . . . . . . .

  • MAE 215: Homework #4

    Instructor: Mark MinerAssigned January 18, 2013

    Due 11:59am, January 23, 2013

    This assignment requires you to use the hw4 starter.m le, available on theHW assignment page. Rename it as asuid hw4.m and perform the required modi-cations. Your submission MUST execute in order to receive full credit.

    Problem 1 Functions Within Functions

    1.1 (10 pts) Euler

    Save and rename the hw4 starter.m le, and use it as the beginning of your code.Recall Eulers formula from analytical calculus: eix = cos(x) + i sin(x), where i isthe imaginary unit. A slight rearrangement yields:

    sin(x) = i cos(x) i eix (1)Create a nested subfunction within the starter le that accepts one input argument

    x (which may be a vector) and returns the sin function dened as above. Callthis function for input arguments of x=0:pi/4:2*pi and return the results to thecommand window.

    1.2 (5 pts) Euler Error

    Subtract the standard MATLAB denition of sin(x) from the above denition forthe same input arguments and return the results to the command window. Thinkabout what this gure means for MATLABs denition of sine.

    1.3 (10 pts) Anonymous

    Corollaries of Eulers formula are the hyperbolic functions, sinh and cosh, which aredened as:

    sinh(x) =ex ex

    2cosh(x) =

    ex + ex

    2(2)

    Using the same starter function, add anonymous functionsmysinh(x) andmycosh(x)which perform the calculations above. Evaluate these functions for input argumentsof x=-0.5:0.1:0.5 and return the output of both functions to the command win-dow.

    . . . . . . . . .

  • MAE 215: Homework #5

    Instructor: Mark MinerAssigned January 23, 2013

    Due 11:59am, January 25, 2013

    Deliverables: One M-le which accepts two inputs (low and high temperatures) in anyof the four units discussed, and yields two outputs (dimensionless eciency and heat ux inW/m2).

    Problem 1 Tricky Temperatures

    Certain common temperature scales are relative, that is, with a zero dened against an arbi-trary value. Others are absolute, taking their zero at the theoretical point where molecularmotion stops. The following functions must ask the user to specify the units on the in-puts, with your code making the necessary adjustments to compute correctly. Faulty inputsmust be rejected (no complex temperatures and only certain scales admit negative). Youmay either admit or reject vectors. You may use either if/else or switch/case struc-tures. Use the menu command to call for inputs. Users must be oered options of degreesFahrenheit, Centigrade, Kelvin or Rankine. If in doubt about temperature scales, consultWikipedia or WolframAlpha. As always, name your function like asurite hw5.m.

    1.1 (10pts) Carnot Eciency

    A heat engine may not have a thermodynamic (1st Law) eciency greater than that of thetheoretical Carnot cycle. This cycle represents the ideal machine taking innite time tomove energy from a hot reservoir at TH to a cold reservoir at TC (perhaps the combustionchamber of a turbine and ambient air). The Carnot/ideal eciency is dened using absolutetemperatures as:

    ideal = 1 TCTH

    (1)

    Write a function which accepts two inputs, TH and TC , and outputs the correct Carnoteciency. Eq. 1 must be given absolute units of temperature. Your function must acceptany of the four input units above.

    1.2 (10pts) Radiation

    The blackbody radiation heat ux between two innite plates (or any pair of objects withview factors of unity) is given by:

    q = (T 4H T 4C) (2)where is the Stefan-Boltzmann constant, and TH and TC are the absolute temperaturesof the interacting black bodies. Given TH and TC as in Q1.1, calculate the output of q.The output must be in units of W

    m2, regardless of the input units. Consult Wikipedia,

    WolframAlpha, or a heat transfer book if you need help nding values of in appropriateunits.

  • MAE 215: Homework #6

    Instructor: Mark MinerAssigned January 25, 2013

    Due 11:59am, January 30, 2013

    Deliverables: One working, commented function or script that accomplishes allobjectives. As always, name it as asuid hw6.m.

    Problem 1 Loops

    1.1 (10pts) while Loops

    The Taylor series allows the approximation of a function at unknown xvalues in theregion of a known value. Thus, if a is the known value and x is near a:

    f(x) f(a) + dfdx

    a (x a) + d

    2f

    dx2a (x a)

    2+ ... (1)

    which can be written compactly as:

    f(x)

    n=0

    f (n)(a)

    n! (x a)n (2)

    where f (n) indicates the nth derivative of the function, and the exclamation markindicates the factorial. Conveniently, ex is its own derivative. Approximate e0.15

    using the Taylor series and a while loop. Note that x = 0.15 is close to a convenientknown a value. Your allowable absolute error (error = |guess true|) is to be lessthan or equal to 109, and you must tell me how many terms in the Taylor serieswere required to achieve convergence. (Suggest using disp)

    1.2 (10pts) for Loops

    The Fibonacci series is dened by creating the next term in the series as the sumof the two prior. For example, if we began with 0 and 1, we would go like: 0+1=1,1+1=2, 1+2=3, 2+3=5, and so on. Taking 1 as the rst term, 1 as the second term,etc., write a for loop to calculate the 50th term in this series.

  • MAE 215: Homework #7

    Instructor: Mark MinerAssigned February 1, 2013

    Due 11:59am, February 6, 2013

    Deliverables: Two pictures and one M-le, though the M-le is optional (butits what I use to assign partial credit if your gures are not perfect). As always,name your M-le as asuid hw7.m.

    Problem 1 Critical Heat Flux

    This assignment requires you to use the hw7 data.mat le, available on the HWassignment page. To load the data in the le into MATLAB, simply save the le toyour working directory (something like Documents/MATLAB/MAE215, hopefully),and then in your code type load hw7 data.mat.

    In the MAT-le, temperature data are split into two matrices, TTC hw carry-ing heated-surface thermocouple data and Tref hw carrying refrigerant temperaturedata. The ve columns of TTC hw are to be labeled B, C, D, F, and G, respectively.The two columns of Tref hw are to be labeled Inlet and Outlet, respectively. Pres-sure data are carried in the two-column matrix p hw, and are to be labeled Inlet andOutlet, respectively. Time is carried in the single-column matrix t.

    1.1 (10 pts) Surface Temperatures

    Plot the time-temperature curves for all of the thermocouples in TTC hw. Providedescriptive axis captions, a legend and a title. If possible, print your gure to PDFfor submission. Otherwise, saving as a JPG is acceptable.

    1.2 (10 pts) Inlet and Outlet States

    Using subplot, display both inlet and outlet pressure vs. time on one subplot. Inthe same gure, make a second subplot and display the inlet and outlet refrigeranttemperatures. For both subplots, provide descriptive axis captions (indicating whichaxis belongs to which data), and provide legends and a title. If possible, print yourgure to PDF for submission. Otherwise, saving as a JPG is acceptable.

    . . . . . . . . .

  • MAE 215: Homework #8

    Instructor: Mark MinerAssigned February 6, 2013

    Due 11:59am, February 8, 2013

    Deliverables: One M-le that executes the required data inprocessing and out-puts the required values and plot.

    Problem 1 Reading and Reckoning

    This assignment requires you to use the hw8 data.csv le, available on the HWassignment page.

    1.1 (5 pts) Incoming

    Using an appropriate command-line data reading function, have your M-le place thecontents of hw8 data.csv into the appropriate workspace of your M-le. Importthe columns of Time (s), Angle (rad), and Speed (m/s).

    1.2 (15 pts) The Blind Navigator

    The data for time, angle, and speed are uniform random values, with directionssplattered around the compass. Working from dead reckoning, and assuming an initialposition of (0, 0), determine the mean x-displacement, the mean y-displacement, andplot the course taken.

    . . . . . . . . .

  • MAE 215: Homework #9

    Instructor: Mark MinerAssigned February 8, 2013

    Due 11:59am, February 13, 2013

    Deliverables: Two JPG les, one text le, and an M-le.

    This assignment requires you to use the hw9 original armstrong.jpg le,available on the HW assignment page. You must submit your M-le, as you arerequired to perform the operations detailed below in the code.

    Problem 1 In Memoriam: Neil Armstrong

    On August 25th of 2012, America lost Neil Armstrong. He was the rst man on themoon, a test pilot, naval aviator, professor, aeronautical engineer, and American hero.On July 20, 1969, he and Buzz Aldrin walked on the moon, while Michael Collins or-bited in the Command-Service Module. The le hw9 original armstrong.jpgcontains a photo of Neil taken by Buzz Aldrin on their way back to Earth. Like manyold images, its colors are somewhat distorted. It is a JPG, so it comes in RGB format.

    1.1 (10 pts) Corrections and Amplications

    Import the picture and apply the following restorative tweaks:Increase the red content by 5%Decrease the green content by 5%Decrease the blue content by 20%

    Write the corrected image to disk (using imwrite) and submit your resultingJPG.

    Photo courtesy of NASA Apollo Archive; Apollo Image Gallery; Author: NASA /Edwin E.Buzz Aldrin, Jr.

    1.2 (10 pts) Fade to Black

    Using the corrected image you obtained in part one, reduce it to black-and-white,write the resulting image to disk (using imwrite) and submit your resulting JPG.

    1.3 (10 pts) By the Numbers

    Using the reduced (m x n x 1) image you obtained in 1.2, write a tab-delimitedASCII text le (.txt extension, i.e., asuid hw9 data.txt) containing the numericalarray representing the image. No headers are necessary. Submit the resulting textdocument.

    . . . . . . . . .

  • MAE 215: Homework #10

    Instructor: Mark MinerAssigned February 13, 2013

    Due 11:59am, February 15, 2013

    Deliverables: Submit one M-le.

    Problem 1 (10 pts) Cells

    Cell arrays are indexed general-purpose buckets. Create an M-le which puts thefollowing objects into one cell array:

    1) A 100x100 magic square (use magic)2) The string The 10th homework3) A vector from 1 to 1000, spaced with increments of 0.14) The square of the vector dened in (3)5) A structure array made by assigning an output while loading the MAT le fromHomework 7.

    Next, call items 3 and 4 back from the cell array and plot them with vector (3)on the x-axis, and vector (4) on the y-axis. No labels or legend are necessary.

    . . . . . . . . .

    Problem 2 (10 pts) Structures

    Structure arrays are named-eld general-purpose buckets. Create an M-le whichputs the following objects into one structure:

    1) A 100x100 random array (use rand)2) The string The 10th homework3) A vector from -1000 to 0, spaced with increments of 0.14) The square of the vector dened in (3)5) The cell array made in Problem 1.

    Next, call items 3 and 4 back from the cell array and plot them with vector (3)on the x-axis, and vector (4) on the y-axis. No labels or legend are necessary.

    . . . . . . . . .

  • MAE 215: Homework #11

    Instructor: Mark MinerAssigned February 15, 2013

    Due 11:59am, February 20, 2013

    Deliverables: Submit one M-le, which outputs the desired image.Required: Data le hw11 dPm.txt from BlackBoard.

    Problem 1 (25 pts) Microchannel Pressure Drop

    Boiling refrigerant in very small channels is an eective way to rapidly remove largeamounts of heat. Such devices are called microchannel evaporators. Large pressuredrops pose a signicant problem to the application of this technology, because smallchannels have large resistance to ow (see Poiseulles Law for the basic idea, but itscales as 1/D4).

    A recent improvement in the eld of microchannel evaporators is the idea ofexpanding the channel cross-section in the ow direction, letting the channel getbigger as more refrigerant boils away to vapor. This improvement is optimizable formaximum heat rejection, and seems to substantially and monotonically reduce thepressure drop in such devices.

    In this assignment, you will produce four linear ts to the four sets of data suppliedin the le hw11 dPm.txt. The le is comma-delimited, and has eight columns ofdata; the odd columns are mass ow rates (g/s), the even are pressure drops (kPa).The data come from the four microchannel evaporators employed to ascertain theexistence of an optimum expansion. They have progressively larger expansion angles,and the nominal angle (in degrees) is noted in the column headers. Mass ow rate isthe independent (x-axis) variable.

    On one gure, plot the four sets of data along with the MATLAB-derived lineart of each (do not use plotyy). Label your axes, add a legend with four entriesidentifying the nominal expansion rate, and title the gure Microchannel PressureDrop. Be sure to use dierent colors and tick-marks for the data sets, and make thet lines the same color as the corresponding data set.

    Note: - The zero- and half-degree expansions have one fewer data point than theone- and two-degree. Do not include the resulting 0, 0 points in your t. You will seewhat I mean when you import the data.

    . . . . . . . . .

  • MAE 215: Homework #12

    Instructor: Mark MinerAssigned February 20, 2013

    Due 11:59am, February 22, 2013

    Deliverables: Submit one M-le, which plots and displays output as required.

    Problem 1 (10 pts) The Syms

    1.1 (5pts) Circles

    Using the MATLAB symbolic environment, dene a parametric circle, as:

    y = cos(t), x = sin(t) (1)

    and plot it for t = [, ].

    1.2 (5pts) Integration

    Evaluate the following symbolically in MATLAB, and be sure the results displayin the command window:

    F =

    100

    1

    dx

    x+ x ln(x) (2)

    G =d

    dx

    (ln(cosh(x2))

    )(3)

    H =

    a

    0

    3 sinh(x

    3

    )dx (4)

    . . . . . . . . .

    Problem 2 (5pts) Structures and Cells

    Create a cell array containing your symbolic objects F , G, and H from 1.2 above,and create a structure containing the x and y objects from 1.1. Display both of theseobjects in the command window.

    . . . . . . . . .

    MAE215_S13A_HW1.pdfMAE215_S13A_HW2.pdfMAE215_S13A_HW3.pdfMAE215_S13A_HW4.pdfMAE215_S13A_HW5.pdfMAE215_S13A_HW6.pdfMAE215_S13A_HW7.pdfMAE215_S13A_HW8.pdfMAE215_S13A_HW9.pdfMAE215_S13A_HW10.pdfMAE215_S13A_HW11.pdfMAE215_S13A_HW12.pdf