DO NOT USE GLOBAL VARIABLES!

Similar documents
ENGR Fall Exam 1

STIPlotDigitizer. User s Manual

Fitting data with Matlab

University of Michigan Department of Aerospace Engineering 5ft 7ft Wind Tunnel Data Acquisition Bible

ENGR Fall Exam 1 PRACTICE EXAM

Assignment 2 in Simulation of Telesystems Laboratory exercise: Introduction to Simulink and Communications Blockset

Basic Stata Tutorial

Engineering 162 Spring The Hewlett-Packard 4145B Semiconductor Parameter Analyzer

AKELA Vector Network Analyzer (VNA) Quick Start Guide

Desktop Command window

Quadratic Functions, Part 1

ENED 1090: Engineering Models I Homework Assignment #2 Due: Week of September 16 th at the beginning of your Recitation Section

Math B Regents Exam 0606 Page 1

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

STAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006

Fitting a Polynomial to Heat Capacity as a Function of Temperature for Ag. by

Interactive MATLAB use. Often, many steps are needed. Automated data processing is common in Earth science! only good if problem is simple

Chapter 3: Introduction to MATLAB Programming (4 th ed.)

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003

ERTH2020 Introduction to Geophysics

WHO STEPS Surveillance Support Materials. STEPS Epi Info Training Guide

The value of f(t) at t = 0 is the first element of the vector and is obtained by

EEN118 LAB FOUR. h = v t ½ g t 2

Curve Fitting the Calibration Data of a Thermistor Voltage Divider

HOTLINE 4.0. Hotline v Page 1 of 11

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

Exploring Parametric Equations With the Human Cannonball

Chapters 6-7. User-Defined Functions

Armstrong Atlantic State University Engineering Studies MATLAB Marina 2D Plotting Primer

ECE 102 Engineering Computation

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

EEN118 LAB FOUR. h = v t ½ g t 2

MATLAB Modul 3. Introduction

A Brief Introduction to MATLAB

Before submitting the file project5.py, check carefully that the header above is correctly completed:

Introduction to MATLAB

PROC REPORT Basics: Getting Started with the Primary Statements

qbal - v1.06 User Manual

SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question.

MATLAB. Devon Cormack and James Staley

APPM 2460 PLOTTING IN MATLAB

KANRI DISTANCE CALCULATOR. User Guide v2.4.9

IQR = number. summary: largest. = 2. Upper half: Q3 =

MAT 275 Laboratory 1 Introduction to MATLAB

EE 301 Signals & Systems I MATLAB Tutorial with Questions

Introduction to FORTRAN

Introduction to Matlab

Your Name: Section: INTRODUCTION TO STATISTICAL REASONING Computer Lab #4 Scatterplots and Regression

ChBE 354 Useful MATLAB Functions

Lab. Manual. Practical Special Topics (Matlab Programming) (EngE416) Prepared By Dr. Emad Saeid

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

9.1 Parametric Curves

Programming Exercise 1: Linear Regression

EEN118 LAB FOUR. h = v t - ½ g t 2

A Quick Guide to Gnuplot. Andrea Mignone Physics Department, University of Torino AA

End of Year Test B. Whole Numbers, Decimals, and Integers. Fractions. Name Date END OF YEAR TEST B. Answers. 5x 2 3y 3x 2y 5 8, 5 2 3, 1

Contents 10. Graphs of Trigonometric Functions

5.2 Functions as Graphs

Introduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)

A Mini-Manual for GNUPLOT

ROSE-HULMAN INSTITUTE OF TECHNOLOGY

Robotics SUMMER 2004 Assignment #4. (SOLUTION) Instructor: Jose Mireles Jr.

Computational lab on complex numbers

Concrete Property Database

f( x ), or a solution to the equation f( x) 0. You are already familiar with ways of solving

Goals: Course Unit: Describing Moving Objects Different Ways of Representing Functions Vector-valued Functions, or Parametric Curves

AMS 27L LAB #2 Winter 2009

An SM tutorial for programming and plotting

Laboratory 1 Octave Tutorial

AnalyzeLoad User s Manual

EEN118 LAB FOUR. h = v t ½ g t 2

A straight line is the graph of a linear equation. These equations come in several forms, for example: change in x = y 1 y 0

Grace days can not be used for this assignment

Math B Regents Exam 0603 Page b For which value of x is y = log x undefined?

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to MATLAB LAB 1

Matlab Review. Dr. Mark Glauser, Created by: David Marr. Mechanical Engineering Syracuse University. Matlab Review p.

3-1 Writing Linear Equations

Review for Quarter 3 Cumulative Test

Chapter 3: Functions and Files

CHEM5302 Fall 2015: Rate Coefficients and Potential of Mean Force for a 2D Potential Model of Protein Folding

The Interpolating Polynomial

ENGINEERING PROBLEM SOLVING WITH C++

Unit 2-2: Writing and Graphing Quadratics NOTE PACKET. 12. I can use the discriminant to determine the number and type of solutions/zeros.

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Automatic Reporting. Real-Time and Wireless Recording and Alarming

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li

EE168 Lab/Homework #1 Introduction to Digital Image Processing Handout #3

PART 1 PROGRAMMING WITH MATHLAB

These notes are to be read in conjunction with the relevant sections of the Instructions for the Conduct of Examination (ICE) for June 2011.

Table of Contents. Introduction.*.. 7. Part /: Getting Started With MATLAB 5. Chapter 1: Introducing MATLAB and Its Many Uses 7

Let s use Technology Use Data from Cycle 14 of the General Social Survey with Fathom for a data analysis project

Final Project. This assignment demonstrates your understanding of the concepts from the CMIS 141 class.

Short Version of Matlab Manual

The equation to any straight line can be expressed in the form:

Two-Dimensional Projectile Motion

ERTH3021 Exploration and Mining Geophysics

Configuring the MultiRanger 200 to measure open channel flow. Specific parameter setting to configure the following primary measurement devices:

Elementary Functions

APPM 2460 Matlab Basics

Transcription:

Problem #1 Use the MATLAB script named trajectory.m. The program plots the ballistic 2-D trajectory of a projectile. The only force acting on the projectile is gravity. As written, the projectile s initial velocity and firing angle are fixed values. The original program is not modular, and it does not incorporate any user-written functions. Requirements Re-write the original program to satisfy the following: Make the program modular by dividing it into a set of subfunctions. o Modify the program to work for any projectile velocity and firing angle. o o Write a subfunction named PromptVelocityAngle that asks the user to enter the following values and return them as output arguments:! Initial projectile velocity (in m/s)! Initial projectile firing angle (in degrees) (You may assume the user will enter only positive velocities and angles.) Write subfunctions to perform these tasks:! Calculate the maximum range name it CalculateMaximumRange It should return the range as an output argument. It should not print anything.! Calculate the maximum height name it CalculateMaximumHeight It should return the height as an output argument. It should not print anything.! Plot the projectile trajectory name it PlotTrajectory Set the lower x-axis limit to 0 m and upper x-axis limit to 2000 m Set the lower y-axis limit to 0 m and upper y-axis limit to autoscale. Include the projectile's initial velocity and angle in the graph s title. Choose an x step size that produces a reasonably smooth curve. It is up to you to decide what type and number of input arguments are needed for each subfunction. Write a primary function named trajectory2 to invoke the PromptVelocityAngle, CalculateMaximumRange, CalculateMaximumHeight, and PlotTrajectory subfunctions. o You can perform any necessary variable setup in the primary function. o The returned max range and max height values should be printed by trajectory2. Save your script using this name: trajectory2.m Note: Use input and output arguments to pass data into and out of the subfunctions. DO NOT USE GLOBAL VARIABLES!

Sample Run (at the Command Window) >> trajectory2 Enter projectile's initial velocity v0 (m/s): 125 Enter projectile's angle theta (degrees) : 60 Maximum range = 1379.37 m Maximum height = 597.29 m

Problem #2 Equation of a general polynomial of degree N: y x + a N N 1 N 2 = a0 x + a 1x + a2 x + K+ a N 1 Example: Third-order polynomial (i.e., degree = 3, so cubic) 3 2 y = 2x 3x + 7x 5 a0 = 2, a1 = 3, a2 = 7, a3 N = 5 File Format For this problem, use a file named data2.txt. The file contains multiple lines, with each line of text following this format: volt,temp o volt Independent column Measured applied voltage (in volts) o temp Dependent column Measured system temperature (in C) The comma character separates the values. Requirements Write a MATLAB program that satisfies the following: Use MATLAB s dlmread function to read the data contained in the data2.txt file. Fit a fourth-order (degree = 4) polynomial to the data. Hint: There is a MATLAB function that does this very efficiently. For the fitted polynomial, determine the values of Vapp at which the temperaure is zero (i.e., the roots of the polynomial). Hint: There is another MATLAB function that does this easily. Display the coefficients of the fitted polynomial and the Vapp crossing values. Plot both the measured data and the fitted polynomial on the same graph. Make your graph look similar to the Sample Run version. Follow the standard rules for making a good graph. Save your program using this name: pfit.m

Sample Run (at the Command Window) >>> pfit Polynomial coefficients are: xxxxx xxxxx xxxxx xxxxx xxxxx xxxxx T crosses zero at: V_app = xxxxx V V_app = xxxxx V NOTE: The polynomial coefficients and zero-crossing values are purposely hidden here. Your program should output your actual calculated numeric values.

Problem #3 Many test and measurement instruments can be connected to a computer via an interface cable (e.g., RS-232 serial or IEEE-488 GPIB). The computer can instruct the instrument to start a measurement. When done, the instrument transfers the data to the computer, where it can be processed. For some instruments, the data is sent as a stream of text which contains a header section that describes the setup/measurement conditions and a data section that contains the actual measured data values. A program running on the computer can receive the stream and store the information as a string. The program then extracts the relevant data from the string. File Format For this problem, use a file named data3.txt. The file contains a single line of text that follows this format: title:date:xlabel:ylabel:numpts:x1,y1, x2,y2,, xnumpts,ynumpts o title A title that describes the measurement setup o date The date the data was measured o xlabel Label for the independent data o ylabel Label for the dependent data o numpts Number of data point pairs o xk,yk Measured values of a data point pair The header section (shown in red) uses the colon character to separate values. The data section (shown in blue) uses the comma character to separate values. Example: My data:12/25/2014:vapp (V):Power (mw):3:1.000000,123.412401,2.500000,321.503142,3.000000,850.230010 title My data date 12/25/2014 xlabel ylabel numpts 3 Vapp (V) Power (mw) (x1,y1) 1.000000, 123.412401 (x 2,y 2) 2.500000, 321.503142 (x 3,y 3) 3.000000, 850.230010 Note: The large number of digits after the decimal point is likely unrealistic, but use them anyway.

Requirements Write a MATLAB program that satisfies the following: Divide the program into primary and secondary functions: Primary function Handles the opening of the data file, invokes a subfunction to extract the header and data, and plots the result Subfunction Processes the string to extract the header information and data values, which it returns back to the primary function. Save your program using this name: plotdata.m Notes: 1. You are allowed to write more than one subfunction, if you decide you need it. 2. Utilize input and output arguments for subfunctions. Do not use global variables. 3. Be sure your program works for any data file that follows the defined format. Specific Requirements for the Primary Function The primary function should be named plotdata. Prompt the user to enter the name of the data file to read. If the file cannot be opened for reading, then print an error message and quit. Use MATLAB s fgetl function to read the data contained in the requested file and store it in a single string variable. Invoke the subfunction and pass it the string as an input argument. Generate a graph using the title, date, labels, and data arrays returned by the subfunction. If you use data3.txt, your graph should look similar to the Sample Run version. Specific Requirements for the Subfunction The input argument is the string read from the file. The output arguments are the extracted parts of the string. Use appropriate string functions and/or array operations to extract the desired information from the string. Hint: There are many ways you can approach this. One excellent method is to utilize MATLAB s strtok function to separate a delimited string into parts. Another useful function is str2num, which can convert a string of text representing numbers into actual numeric arrays.

Sample Run (at the Command Window) >>> plotdata Enter the name of the data file: data3.txt

Problem #4 You are a programmer working for a team that is performing medical research on a small population of volunteers. These people submitted some personal information that has been stored in a text file. It is your job to develop software that can read the file and create a searchable database which allows researchers to select just those people who meet certain study criteria. File Format For this problem, use a file named data4.txt. The file contains multiple lines, with each line of text following this format: ID, lname, fname, sex, age, height, weight, smokes, drinks, state o ID Unique identification number assigned to the person o lname Last name o fname First name o sex Genetic male (M) or female (F) o age Age (years) o height Height (foot:inches) o weight Weight (US pounds) o smokes Does the person smoke? (Y or N) o drinks Does the person drink alcohol? (Y or N) o state State of permanent residence (CA, OR, WA for this study) The comma character separates the values. Example: 43210, Smith, Laura, F, 35, 5:7, 128, N, Y, CA ID 43210 lname fname sex age height weight smokes drinks state Smith Laura Female 35 years 5 foot 7 inches 128 pounds No Yes CA (i.e., California)

Requirements Write a MATLAB program that satisfies the following: Read the data from the data4.txt file and store it in an array of structures. Hint: The strtok function is very useful here to break up each string. Each structure in the array should contain information for one person only. Use the labels described in the file format section for the structure s field names. Decide for yourself the best data type (e.g., string or number) to use for each field. Prompt the user to enter values for the following search criteria: Sex (Valid responses: M or m for male, F or f for female) Age lower limit (integer number) Age upper limit (integer number) Does the person smoke? (Valid responses: Y or y for yes, N or n for no) Does the person drink alcohol? (Valid responses: Y or y for yes, N or n for no) Loop through the array of structures and display only those people whose data matches the search criteria. Show the full information of each selected person in a nicely formatted way. Example: Search criteria: Sex= M, AgeLL=20, AgeUL=42, Smoke= Y, Drink= N This means that only those people who are male AND with 20 age 42 AND who do smoke AND who do not drink should be displayed. Make your program reasonably modular. Save your program using this name: dbase.m

Sample Data 31241, Jones, Martha, F, 26, 5.3, 125, Y, N, CA 34242, Shepard, Julia, F, 35, 5.5, 145, N, N, CA 46235, Metcalf, Robert, M, 18, 5.11, 145, N, N, OR 29001, Pine, Devon, M, 24, 5.4, 155, N, Y, WA 10244, Archer, Rachel, F, 30, 5.4, 125, N, N, OR 15932, Louis, Mark, M, 56, 6.1, 175, N, Y, OR 22911, Francis, Carl, M, 22, 5.8, 150, N, Y, OR 53221, Packard, Joseph, M, 42, 5.10, 170, N, Y, WA 19732, Scott, Presley, M, 29, 6.1, 225, N, Y, WA 22511, Spears, Jenny, F, 16, 5.2, 130, N, N, CA 11291, Alvarez, James, M, 38, 5.7, 162, Y, N, OR 83212, Cannon, Sean, M, 45, 5.10, 285, N, N, OR 58192, Ruiz, Sandra, F, 25, 5.8, 130, Y, N, CA 58199, Chan, David, M, 24, 5.3, 140, N, N, WA 75431, Hogan, Grace, F, 60, 5.3, 110, N, N, CA 89673, Prentiss, Mary, F, 26, 5.5, 126, Y, Y, OR 97863, Lopez, Christina, F, 19, 5.4, 120, N, N, WA 97243, Cooper, Candice, F, 47, 5.9, 132, N, Y, OR 68423, McClure, Niki, F, 30, 5.2, 126, N, N, OR 89011, Lawson, Carter, M, 65, 6.2, 210, N, Y, OR 80721, Lawrence, Michael, M, 58, 5.9, 170, Y, Y, CA Sample Run (at the Command Window) >> dbase Enter search criteria: Sex (M/F): m Age lower limit: 20 Age upper limit: 35 Smokes (Y/N)? y Drinks (Y/N)? n No person fits that search criteria. >> dbase Enter search criteria: Sex (M/F): m Age lower limit: 30 Age upper limit: 50 Smokes (Y/N)? y Drinks (Y/N)? n ID# 11291 Name: Alvarez, James Sex : Male Age : 38 yrs Height: 5' 7" Weight: 162 lbs Smokes: Yes Drinks: No State : OR

>> dbase Enter search criteria: Sex (M/F): m Age lower limit: 20 Age upper limit: 50 Smokes (Y/N)? n Drinks (Y/N)? y ID# 29001 Name: Pine, Devon Sex : Male Age : 24 yrs Height: 5' 4" Weight: 155 lbs Drinks: Yes State : WA ID# 22911 Name: Francis, Carl Sex : Male Age : 22 yrs Height: 5' 8" Weight: 150 lbs Drinks: Yes State : OR ID# 53221 Name: Packard, Joseph Sex : Male Age : 42 yrs Height: 5' 10" Weight: 170 lbs Drinks: Yes State : WA ID# 19732 Name: Scott, Presley Sex : Male Age : 29 yrs Height: 6' 1" Weight: 225 lbs Drinks: Yes State : WA

>> dbase Enter search criteria: Sex (M/F): F Age lower limit: 15 Age upper limit: 40 Smokes (Y/N)? N Drinks (Y/N)? N ID# 34242 Name: Shepard, Julia Sex : Female Age : 35 yrs Height: 5' 5" Weight: 145 lbs Drinks: No State : CA ID# 10244 Name: Archer, Rachel Sex : Female Age : 30 yrs Height: 5' 4" Weight: 125 lbs Drinks: No State : OR ID# 22511 Name: Spears, Jenny Sex : Female Age : 16 yrs Height: 5' 2" Weight: 130 lbs Drinks: No State : CA ID# 97863 Name: Lopez, Christina Sex : Female Age : 19 yrs Height: 5' 4" Weight: 120 lbs Drinks: No State : WA ID# 68423 Name: McClure, Niki Sex : Female Age : 30 yrs Height: 5' 2" Weight: 126 lbs Drinks: No State : OR