EGR 103/Spring 2015/Lab 2

From PrattWiki
Jump to navigation Jump to search

2.1 Introduction

The main purpose of this lab is to go through the process of writing a complete program to load a data set, manipulate the values, perform some analysis, and create a graph. The following is a companion piece to the lab handout itself. The sections in this guide will match those in the handout.

2.2 Resources

You will want to have a browser open with the MATLAB:Script and MATLAB:Plotting pages available to you.

2.3 Getting Started

As with last week, you will want to use the

ssh -XY netid@login-teer.oit.duke.edu

command in MobaXterm to connect to a Teer machine. Follow the directions to connect, change into your EGR103 directory, make a new folder, change into it, copy things, then make a copy of your lab. Finally, start MATLAB.

2.3.1 Preview

Read and work through this section, taking notes as you go on what is discussed.

2.3.2 .m Files

Read and work through this section, taking notes as you go on what is discussed.

2.4 Cantilever Beam Analysis

Read and work through this section, taking notes as you go on what is discussed, especially how the equation was arranged to get displacement as a function of force based on how the experiment was conducted.

To see the data set, go to UNIX and type

more Cantilever.dat

You will see an 8x2 array of data. The first column of numbers is the amount of mass in kg placed on the end of the beam - for this experiment, it ranged from 0 to about 0.8 kg (i.e. about 8 N). The second column of numbers if the displacement measured in inches, because that is what the device I used measures in. You should always take data in the original units of the device; you can convert it later.

Typically, data sets should have descriptions such as the items in the data set, units, perhaps the equipment and the person who took the measurements. For this week, however, I wanted to give you a rectangular array of data that MATLAB can easily load.

2.5 Creating the Script

Note when you open a second scripts that there are tabs in the editing window; you can choose which one to make active by clicking its tab.

2.5.1 Lab Manual Syntax

Read this section, taking notes as you go on what is discussed.

2.5.2 Comments

While you are not explicitly required to include comments in your labs -- other than the header and community standard information at the top = comments are a great way to tell yourself and your TAs what you meant to do with particular chunks of code.

2.5.3 Initializing the Workspace

Read and work through this section, taking notes as you go on what is discussed; note that there are several items you will simply be typing into the command window rather than your code.

2.5.4 Loading and Manipulating the Data

Read and work through this section, taking notes as you go on what is discussed.

2.5.5 Generating Plots

Read and work through this section, taking notes as you go on what is discussed. Note that the code for this is pretty far under what you've written so far; you will be filling in the blank space later, just like Taylor Swift.

For the "During the lab, the instructor will have you create several different graphs in the command window..." go ahead and look at the following alternate plotting commands:

plot(Cantilever)

Plots the matrix itself - the data points are plotted by columns with the y value coming from the data points and the x value coming from the row of the matrix. That is why there are two lines (two columns of data) and the domain goes from 1 to 8.

plot(Force, Displacement, 'mp')

Uses purple pentagrams. It's adorable, though perhaps not professional.

plot(Force, Displacement, 'bh')

Using symbols that have cultural or religious meanings should be avoided unless wholly appropriate to the data set. Which is why we're just going to go ahead and use circles. On you own, however, try to get MATLAB to create a graph with red squares connected by a red dashed line.

2.5.6 Polynomials in MATLAB

Read and work through this section, taking notes as you go on what is discussed. I have no idea why Table 2.1 ended up starting its own page...

2.5.7 Generate Predictions

Read and work through this section, taking notes as you go on what is discussed. This part creates a new set of data points based on your equation so that you can actually plot it.

2.5.8 Generating Plots (revisited)

Read and work through this section, taking notes as you go on what is discussed. This part adds the new line to your old graph.

CRITICALLY IMPORTANT PART - never put an ending on the filname of a print command in MATLAB. MATLAB will automagically add the correct extension (for us, typically .ps) if there is not one, but if you put one, MATLAB will save the file to exactly that name. It could be a disaster if, for example you give a filename like lab2.tex...

2.6 The Assignment

Basically, once you get this script running perfectly, you are going to replicate it three times and change it to use three different data sets. Note: these three data sets are "cooked" - that is, I produced them; they did not come from an experiment.

2.6.1 What the .m-files Should Do

Read and work through this section, taking notes as you go on what is discussed.

2.6.2 The Lab Report

Read and work through this section, taking notes as you go on what is discussed. Note that the data sets have different numbers of points so the bottoms of the data tables will not line up. Also note that you should use the original data (masses and displacements in inches) in the tables.

2.6.3 Processing the Lab Report

Among other things, OIT has the system set up to use A4 paper instead of US Letter. You should change that. Also, you need to know how to create a PDF to upload your Lab 1. Both answers are at Welcome_Back#New_for_Spring.2C_2015