14 views

Original Title: E7_HW4_Fall2017

Uploaded by Jerry Wu

E7_HW4_Fall2017

njhjh

© All Rights Reserved

- Additional Math 0606 Nov 15_ms_23
- Line Item Level Data Extraction for Financial Accounting and Controlling
- (Lecture Notes in Computer Science 4581) Alexandre Petrenko, Margus Veanes, Jan Tretmans, Wolfgang Grieskamp-Testing of Software and Communicating Systems_ 19th IFIP TC 6_WG 6.1 International Conferen
- Guitar Strings
- Data Structure
- Properties of Triangles
- Fsc Notes Phy1
- SHIP SHOCK TRIAL SIMULATION OF USS Winston S. Churchill (DDG 81) SURROUNDING FLUID EFFECT.pdf
- Mathhigher4H
- Fabrication Calculation
- Physics Paper 1 C2 July PDF
- Matlab Graph
- Waves and Sound Waves
- Sound and Music Review
- Structure
- 5018679
- Fisika fikssasi
- Chapter 6 Waves 2016
- Sec10Sonic Theory
- Ex_10_1_FSC_part1

You are on page 1of 7

Engineers

University of California, Berkeley, Fall 2017

Instructor: Michael Frenklach

Lab 4

Due: October 6, 2017 at 11:59 pm

The purpose of this lab is to develop familiarity with cell arrays, structures, tables, plotting and

debugging.

Use only functions contained in the basic MATLAB installation; do not use functions from optional toolboxes

(e.g. curve-fitting toolbox, optimization toolbox, etc.).

For this assignment, please submit the following to bCourses: function files addGameCell.m,

addGameStruct.m debugPlot.m in a zip-file named lastname firstname hw4.zip.

Cell arrays are arrays that can store arrays and/or values of different datatypes, and are very useful. Here

we will create a cell array that keeps track of the California Golden Bears 2017 football season to date.

Cals results through last week are shown in the table below.

Home Team Away Team Home Team Score Away Team Score Winner

UNC Cal 30 35 Cal

Cal Weber State 33 20 Cal

Cal Ole Miss 27 16 Cal

Cal USC 20 30 USC

Create a cell array that incapsulates the data above in the same order. When complete, your cell array

should look like the following:

>> CalSchedule

CalSchedule =

3 x5 cell array

Cal Weber State [33] [20] Cal

Cal Ole Miss [27] [16] Cal

This exercise will not be graded.

1

Homework Problem 1: Cell arrays

function [ schedule ] = addGameCell ( schedule , hometeam , awayteam ,

homescore , awayscore )

where: schedule is a cell array with the same format as CalSchedule in Exercise 1 that holds the current

data (home team, away team, home score, away score and winner) and will be expanded to include a new

game, hometeam is a character array of the home team, awayteam is a character array of the away team,

homescore is the home teams final score and awayscore is the away teams final score.

Your function should be able to reproduce the following sequence:

>> calSchedule = addGameCell ({} , UNC , Cal , 30 , 35)

calSchedule =

1 x5 cell array

calSchedule =

2 x5 cell array

Cal Weber State [33] [20] Cal

calSchedule =

3 x5 cell array

Cal Weber State [33] [20] Cal

Cal Ole Miss [27] [16] Cal

function [ schedule ] = addGameStruct ( schedule , hometeam , awayteam ,

homescore , awayscore )

2

where: schedule is a structure (with fields hometeam, awayteam, homescore, awayscore, winner) that

holds the current data and will be expanded to include a new game, hometeam is a character array of the

home team, awayteam is a character array of the away team, homescore is the home teams final score and

awayscore is the away teams final score.

Your function should be able to reproduce the following sequence:

>> calSchedule = addGameStruct ( struct , UNC , Cal , 30 , 35)

calSchedule =

struct with fields :

hometeam : UNC

awayteam : Cal

homescore : 30

awayscore : 35

winner : Cal

calSchedule =

1 x2 struct array with fields :

hometeam

awayteam

homescore

awayscore

winner

calSchedule =

1 x3 struct array with fields :

hometeam

awayteam

homescore

awayscore

winner

ans =

struct with fields :

hometeam : Cal

awayteam : Ole Miss

homescore : 27

awayscore : 16

winner : Cal

3

Exercise 2: Tables

Create a table that stores the same information as the cell array in Problem 1 and the structure in Problem

2.

This exercise will not be graded.

Exercise 3: Plotting

Waves are important for every discipline of engineering. When considering sampled data of waves, a common

problem is aliasing, which is when a wave appears to have a longer period due to infrequent sampling.

Visualize this effect for yourself by plotting a simple sine wave from 0 to 12 radians using 10, 20 and 200

points on the same plot. You will notice that the 200-point wave appears to be completely smooth, the

20-point wave does not have a high enough sampling frequency to accurately capture the wave but is not

aliased, and the 10-point wave appears to have a period of 4 (rather than 2).

Your result should look identical to fig. 1, including title, axis labels and legend.

4

Exercise 4: Subplots

With this assignment you are given a MATLAB data file dx0025 203m.mat which contains three two-

dimensional arrays, udata, vdata, wdata, which are the three velocity components ~u = (u, v, w) for a

horizontal plane (203 meters above the surface) in a turbulent atmospheric simulation. The horizontal res-

olutions x and y are both 25 meters (i.e. the distance between each point and its neighbor in either the

x- or y-direction is 25 meters).

function [] = p l o t V e l o c i t y C o m p o n e n t s ( plottingFunction , u , v , w , dx , nx )

where: plottingFunction is a handle to the type of plot to be used, u, v, w are the three two-dimensional

arrays to be plotted, dx is the horizontal resolution of the data (assume x = y ) and nx is the number of

points to plot (assume the same number of points are used in x- and y-directions).

You can load the data in the .mat file to your workspace using the command load dx0025 203m.mat. The

input data should be loaded before calling your function and passed as arguments; the file

should not be loaded inside the function.

Your figure should have three subplots, one for each velocity component (see figs. 2, 3). Each subplot should

have a title, labels on both axes and a colorbar (with a label).

Figure 2: u-, v- and w-velocity contours of data from dx0025 203m.mat using plottingFunction =

@contourf, dx = 25 and 100.

Figure 3: u-, v- and w-velocity contours of data from dx0025 203m.mat using plottingFunction =

@contour, dx = 25 and 500.

5

Homework Problem 3: Debugging

You are given a file debugPlot.m that is trying to produce a 3D surface plot with contours below the surface

(using surfc) of

however it has some errors. Debug the code so that the code runs without errors and produces a figure that

matches fig. 4.

The function should take the number of points to use in both x and y as a single input argument (square

domains only) and return the z data being plotted. There should be a point every 0.1 radians in x and y

directions on your grid.

Currently, the function is:

function [ z ] = debugplotting ()

dx = 0.1 pi ;

x = linspace (0 , nx * dx , nx ) ;

y = linspace (0 , nx * dx , nx ) ;

wave2 = makewave ([0 ,1] , cos ) ;

wave3 = makewave ([200 ,20] , sin ) ;

wave4 = makewave ([1 ,1] , sin ) ;

surfc (x ,y , z ) ;

title ( Some Waves )

xlabel ( x )

ylabel ( y )

zlabel ( amplitude )

6

Figure 4: Plot of waves generated by the function debugWaves for nx = 100.

- Additional Math 0606 Nov 15_ms_23Uploaded byCorinSaputra
- Line Item Level Data Extraction for Financial Accounting and ControllingUploaded byvijayam_44
- (Lecture Notes in Computer Science 4581) Alexandre Petrenko, Margus Veanes, Jan Tretmans, Wolfgang Grieskamp-Testing of Software and Communicating Systems_ 19th IFIP TC 6_WG 6.1 International ConferenUploaded byAndrés Mariano
- Guitar StringsUploaded byantoniobh
- Data StructureUploaded bySaloni Singhal
- Properties of TrianglesUploaded byavs
- Fsc Notes Phy1Uploaded byelizabeth_connor007
- SHIP SHOCK TRIAL SIMULATION OF USS Winston S. Churchill (DDG 81) SURROUNDING FLUID EFFECT.pdfUploaded byFernando Raúl LADINO
- Mathhigher4HUploaded byVarun Panicker
- Fabrication CalculationUploaded bykoyahassan
- Physics Paper 1 C2 July PDFUploaded byMohammad Irfan
- Matlab GraphUploaded bydiex1001
- Waves and Sound WavesUploaded byShivendra Agarwal
- Sound and Music ReviewUploaded byRyan Mills
- StructureUploaded byHart Quiambao
- 5018679Uploaded bySeverina Mallari
- Fisika fikssasiUploaded byarul
- Chapter 6 Waves 2016Uploaded byPikachu Alsaleh
- Sec10Sonic TheoryUploaded byDennise Shughni
- Ex_10_1_FSC_part1Uploaded byMuzammil Hasnain
- List of ProgUploaded byHarshitGaur
- MC0066Uploaded byAnil Kumar Sharma
- As GlossaryUploaded byManraj Besal
- Principles of PhysicsUploaded byHarold Manga
- Laws & DefinitionUploaded bySiti Salmah Erang
- Tutorial EsmUploaded bykamiruddin
- Step3 Carlos EchavarriaUploaded byDiegoStivenRubioMoreno
- Frog and Ps Frog a Study of Two Reactionless Ocean Wave Energy ConvertersUploaded byFernandoMartínIranzo
- ch10Uploaded byDavid Brantley
- 4-Quadratic Surfaces.pdfUploaded byslowjams

- ap04_sg_gopo_us_37090Uploaded byJerry Wu
- How to install.txtUploaded byJerry Wu
- Back to December - Taylor Swift (Piano Sheet)Uploaded byMelinna Levitia Kartahardja
- Equation SheetUploaded byJerry Wu
- ap11_us_govt_politics_q4.pdfUploaded byJerry Wu
- _ap07_us_go_po_sgs_final.pdfUploaded byJerry Wu
- ME40_F2018_HW9(Chap11)Uploaded byJerry Wu
- UCOP Concussion Education TrainingUploaded byJerry Wu
- 3199-Article Text PDF-6957-1-10-20130718.pdfUploaded byTeto
- Download File (3)Uploaded byJerry Wu
- prob7Uploaded byJerry Wu
- lecture22bwUploaded byJerry Wu
- Pain Pain Go AwayUploaded byJerry Wu
- Guang Liang - Tong Hua (piano).pdfUploaded byJerry Wu
- Lecture 04Uploaded byJerry Wu
- E25 HW#01 F17Uploaded byJerry Wu
- Standard SErpentUploaded byghionoiuc
- E7_outline_F17 (3)Uploaded byJerry Wu

- Soros Funded GroupsUploaded bystormyweather
- Seeing in the Red: Looking at Student DebtUploaded byCurtis Marez
- greatnessfinal[1]Uploaded bysmf 4LAKids
- MARGINSON the Dream is OverUploaded bymarxelojulious
- A State of Open Mind Magazine_Spring 2013_webUploaded byCal Humanities
- BerkeleyUploaded byArt Bueno
- angela tang-tan resumeUploaded byapi-459113948
- Sikholars 2012 ProgramUploaded byJakara Movement
- Landscape ArchitectureUploaded byShweta Dekate
- Rubinstein MarkUploaded bypremseoul
- High Frequency Trading - Maureen O MaraUploaded byanjay_71
- General Counsel Chief Legal Officer In San Francisco Bay CA Resume Thomas McKeeverUploaded byThomas McKeever
- cp46Uploaded bya
- Sacramento Business ReviewUploaded byCapital Public Radio
- Park PaulayUploaded bytrabajosic
- Spring BanquetUploaded bygaarasteddybear
- fema-353Uploaded byJANJGM
- Obituario de a. L. Kroeber, Por Julian StewardUploaded byferbalbi
- Judicial Profile: Coleman Blease, 3rd District Court of Appeal CaliforniaUploaded byCalifornia Judicial Branch News Service - Investigative Reporting Source Material & Story Ideas
- Philippa Levine CVUploaded byAnonymous H0ySr9Pg
- 800 Free Online CoursesUploaded byAleksandra Voinea
- le cv 08-2017Uploaded byapi-368414725
- 2014 PIA NewsletterUploaded byphilaid
- Willard LibbyUploaded bybakex645
- Ganguli.cvUploaded bySaurav Ågarwal
- DESALINATION, WITH A GRAIN OF SALT (CA, 2006)Uploaded bySergey Frolov
- 1.Plenary-English.pdfUploaded byBopit Khaohan
- Unknown - Berkeley in the Sixties - ScriptUploaded byStephanie Roberts
- Phi Delta Theta - Alpha Star Spring 2012Uploaded byPhi Delta Theta - California Alpha at UC Berkeley
- Batta - CV - Jan 2011Uploaded byeville89