Armstrong State University Engineering Studies MATLAB Marina Algorithm Development I Primer

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

Armstrong State University Engineering Studies MATLAB Marina Switch-Case Statements Primer

Since a projectile moves in 2-dimensions, it therefore has 2 components just like a resultant vector: Horizontal Vertical

Math Learning Center Boise State 2010, Quadratic Modeling STEM 10

Projectile Trajectory Scenarios

Armstrong Atlantic State University Engineering Studies MATLAB Marina Sorting Primer

(ii) Calculate the maximum height reached by the ball. (iii) Calculate the times at which the ball is at half its maximum height.

Date Course Name Instructor Name Student(s) Name WHERE WILL IT LAND?

ME 105 Homework 4 A Movie Stunt Simulation with Graphical User Interface

Precalculus 2 Section 10.6 Parametric Equations

Chapter Five: Functions

Armstrong State University Engineering Studies MATLAB Marina 2D Arrays and Matrices Primer

Preview. Two-Dimensional Motion and Vectors Section 1. Section 1 Introduction to Vectors. Section 2 Vector Operations. Section 3 Projectile Motion

Zero Launch Angle. since θ=0, then v oy =0 and v ox = v o. The time required to reach the water. independent of v o!!

2.3 Projectile Motion

PROJECTILE. 5) Define the terms Velocity as related to projectile motion: 6) Define the terms angle of projection as related to projectile motion:

Vector Decomposition

20/06/ Projectile Motion. 3-7 Projectile Motion. 3-7 Projectile Motion. 3-7 Projectile Motion

Projectile Launched Horizontally

Section 5: Quadratics

OCR Maths M2. Topic Questions from Papers. Projectiles

Purpose of the experiment

Return Values SECTION /26/16 Page 33

SPH3U1 Lesson 12 Kinematics

Practice Exams. Exam logistics. Projectile Motion Problem-Solving. ax = 0 m/s2 ay = -9.8 m/s2. You won t do well if you wait then cram.

Contents 10. Graphs of Trigonometric Functions

Lesson 3.1 Vertices and Intercepts. Important Features of Parabolas

Projectile Motion. Photogate 2 Photogate 1 Ramp and Marble. C-clamp. Figure 1

Review for Quarter 3 Cumulative Test

Projectile Motion SECTION 3. Two-Dimensional Motion. Objectives. Use of components avoids vector multiplication.

Quadratic Functions, Part 1

Math 4: Advanced Algebra Ms. Sheppard-Brick A Quiz Review LT ,

AA Simulation: Firing Range

Two-Dimensional Motion

Step 2: Find the coordinates of the vertex (h, k) Step 5: State the zeros and interpret what they mean. Step 6: Make sure you answered all questions.

Applied Parabolas: Catapult (one test grade)

Contents 10. Graphs of Trigonometric Functions

CHAPTER 2. Polynomials and Rational functions

We ve defined vectors as quantities that have a magnitude and a direction Displacement, velocity, and acceleration Represent by an arrow whose length

Name Period. (b) Now measure the distances from each student to the starting point. Write those 3 distances here. (diagonal part) R measured =

Learning Objectives. Math Prerequisites. Technology Prerequisites. Materials. Math Objectives. Technology Objectives

LAB 03: The Equations of Uniform Motion

1. Introduction to Programming

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

2. The diagram shows part of the graph of y = a (x h) 2 + k. The graph has its vertex at P, and passes through the point A with coordinates (1, 0).

Ball Toss. Data Pro program. 2. Make a sketch of your prediction for the velocity vs. time graph. Describe in words what this graph means.

Goals: - to be able to recognize the position-time, velocity-time and acceleration-time graphs of each of these main types of motion:

Projectile Motion. Remember that the projectile travels vertically (up and down y) in the same time that it is traveling above the horizontal (x)

Automatic Pouring Robot. Akilah Harris-Williams Adam Olmstead Philip Pratt-Szeliga Will Roantree

Section 9.1 Identifying Quadratic Functions Section 9.2 Characteristics of Quadratics

Falling Balls. Names: Date: About this Laboratory

Introduction to Graphing Quadratics

Edexcel Mechanics 2 Kinematics of a particle. Section 1: Projectiles

Name Class Date. Activity P37: Time of Flight versus Initial Speed (Photogate)

Unit 1 Quadratic Functions

Quick. ClassPad II. Reference Guide. Press these keys for numbers, basic operations, and the most common variables

Chapter 3 Practice Test

Unit 2: Functions and Graphs

PreCalculus Chapter 9 Practice Test Name:

Projectile Motion. A.1. Finding the flight time from the vertical motion. The five variables for the vertical motion are:

Lab 4 Projectile Motion

CS 1044 Project 1 Fall 2011

PRECALCULUS MATH Trigonometry 9-12

Quadratic Functions (Section 2-1)

ANONYMOUS FUNCTIONS... 1 Using Anonymous Functions with Arrays... 4

ROSE-HULMAN INSTITUTE OF TECHNOLOGY

Exploring Projectile Motion with Interactive Physics

Center #1. 3. There is a rectangular room whose length is 8 times its width. The area of the room is 32 ft 2. Find the length of the room.

Projectile Motion. Honors Physics

MATH 1101 Exam 4 Review. Spring 2018

Chapter 3: Vectors & 2D Motion. Brent Royuk Phys-111 Concordia University

7-5 Parametric Equations

Neatly print first and last names: Exam II. "On my honor, as an Aggie, I have neither given nor received unauthorized aid on this academic work.

MATLAB. Data and File Management

Stomp Rocket Lab Physics

Free Fall. Objective. Materials. Part 1: Determining Gravitational Acceleration, g

2-D Motion: Projectiles at an Angle Physics

Y. Butterworth Lehmann & 9.2 Page 1 of 11

KCS Motion. Video Motion Analysis Software

Semester 2 Review Problems will be sectioned by chapters. The chapters will be in the order by which we covered them.

Lesson 17: Graphing Quadratic Functions from the Standard Form,

CS116X Midterm Review Winter 2015

Week 8 Problems. #2 Points possible: 1. Total attempts: 2 Enter your answer rounded to two decimal places.

Honors Pre-Calculus. 6.1: Vector Word Problems

Name. Beaumont Middle School 8th Grade, Advanced Algebra I. A = l w P = 2 l + 2w

Chapter 4: Programming with MATLAB

Find the component form and magnitude of the vector where P = (-3,4), Q = (-5, 2), R = (-1, 3) and S = (4, 7)

Introduction to Simulink

Air Resistance Lab Discovery PSI Physics Dynamics

Section 1.5 Transformation of Functions

2. Find the muzzle speed of a gun whose maximum range is 24.5 km.

Study Guide and Review - Chapter 10

Study Guide and Review - Chapter 10

Section 1.5 Transformation of Functions

Computational Methods of Scientific Programming Fall 2007

5. Selection: If and Switch Controls

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

II. Functions. 61. Find a way to graph the line from the problem 59 on your calculator. Sketch the calculator graph here, including the window values:

Practice problems from old exams for math 233

Recitation 1-6 Projectile Motion

Transcription:

Armstrong State University Engineering Studies MATLAB Marina Algorithm Development I Primer Prerequisites The Algorithm Development I Primer assumes knowledge of the MATLAB IDE, MATLAB help, arithmetic operations, built in functions, and scripts. Material on these topics is covered in the MATLAB Marina Introduction to MATLAB module. Learning Objectives. Be able to write algorithms to solve sequential problems.. Be able to implement sequential algorithms using MATLAB. Terms algorithm, stepwise refinement MATLAB Functions, Keywords, and Operators none Algorithms Algorithms are the logical recipes that underlie computer programs. Virtually all disciplines now rely on some form of algorithmic model: medicine, economic theory, social theory, etc. Computer programs express algorithms in a particular programming language. The goal is to take something that can be done in a human mind and use a computer to perform the mind s work. Algorithms must be precise and unambiguous. Consider generating an algorithm to brew coffee. Assumptions: will make cowboy coffee (in a pot on the stove). Figure a shows an imprecise sequence of steps to make coffee and Figure b shows a more precise sequence of steps to make coffee. Get a pot Fill with water Place on stove Heat water Add coffee Turn off heat Let sit Pour into cup Figure a, Algorithm (not precise) Get a two quart saucepan Fill with one quart of tap water Place on stove Heat water to 0 degrees F Add 8 Tablespoons coffee ( Tbsp per cup of water) Turn off heat Let sit for 4 minutes Pour coffee through a strainer into cup Figure b, Algorithm (more precise)

There may be a need for additional algorithms that precisely describe how to get the pot (where it is, how to recognize a saucepan), how the coffee should be ground (is it pre-ground or does it need to be ground, where the coffee grinder is located and how to grind if not preground), how to heat things on a stove, etc. Algorithms for computer programs need to be precise, more like the sequence of steps of Figure b. Stepwise Refinement Larger more complex problems are typically solved by breaking the problem up into smaller problems each of which is relatively easily solved or has been solved before. This is called stepwise refinement. The solutions to the smaller problems are integrated into a solution for the larger problem. A general procedure for solving large complex problems is:. Decompose the larger problem into smaller subproblems.. Continue decomposing the subproblems until you obtain subproblems that are manageable (easily solvable or already solved). 3. Solve each subproblem and use these solutions to solve the more complex subproblems and finally the original problem. Keep your initial problems general and add details as necessary. Do not worry about program syntax until you are ready to solve the subproblems. Some additional tips: Solve the sample problem using a set of data by hand. If you cannot solve the problem, you will not be able to write an algorithm to solve the problem. It is often helpful to describe the problem from an input output perspective, i.e. what information does the program need to solve the problem and what must be calculated. Logic errors (errors in the algorithm) will generally not be caught until the program is tested. Just because a program compiles and links successfully does not mean it works. Compilers/linkers catch syntax errors, not logic errors. Test your solution with some fairly simple data that you can verify by hand and then with a reasonable number of sets of additional data (both valid and invalid). It is here where you will catch any logic errors. Problem Solving Example Write a MATLAB program to determine if a thrown snowball will hit a target. Problem analysis: Have we been given enough information to solve the problem? If not, what do we need to be able to solve the problem? Determining if a thrown object hits a target involves projectile motion (physics). The equations of motion in two dimensions are:

s = s + v t+ g t x x0 x0 x s = s + v t+ g t y y0 y0 y Where s is position, v is velocity (speed plus direction), g is the acceleration due to gravity, and t is time. To determine if a projectile hits a target we need to know the location of the target relative to the initial location of the projectile, i.e. how far away (horizontal and vertical distance) is the target from the thrower. We will also need to know the initial velocity and initial direction of the projectile (how hard and in what direction was the snowball thrown) and the size of the target. Assuming that gravity is constant, that the target does not move and is at position ( x, y) the thrower is stationary with initial position ( sx0 0, sy0 height) s s, that = =, and that the snowball does not lose any energy due to air resistance: The inputs to the program will be the initial velocity v 0 (how hard thrown), initial height (how tall is thrower), and release angle of the snowball (direction thrown). The program will determine and output if the target was hit. The program must determine if the target is in the snowball s path of motion. The program will need to solve for the time it takes for the snowball to reach the target and the height of the snowball at that time, i.e. what is the height of the snowball when it covers the horizontal distance to the target. The program can then check if this height is within the area occupied by the target. Initial Algorithm: Read in the horizontal and vertical distance to the target. Read in the initial velocity and release angle of the snowball. Determine if snowball hit target. Output whether snowball hit or missed target. Further refining the determination if the snowball hit the target: Calculate the x and y components of the snowball s velocity. Calculate the time it takes the snowball to reach the target. Calculate the height of the snowball when it reaches target. Determine if snowball height is less than the target height. If yes, the snowball hit the target. Final Algorithm: Read in the horizontal and vertical distance to the target. Read in the initial velocity and release angle of the snowball. Determine if snowball hit target. a) Calculate the x and y components of the snowball s velocity. b) Calculate the time it takes the snowball to reach the target. c) Calculate the height of the snowball when it reaches target. 3

d) Determine if snowball height is less than the target height. If yes, the snowball hit the target. Output whether snowball hit or missed target. A comment skeleton corresponding to the algorithm is shown in Figure a. The coded program is shown in Figure b. % Horizontal and vertical distance to the target % Initial velocity and release angle of the snowball % Determine if snowball hit target % Calculate the x and y components of the snowball s velocity % Calculate the time it takes the snowball to reach the target % Calculate the height of the snowball when it reaches target % Determine if snowball height is less than the target height % Output whether snowball hit target. Figure a, Comment Skeleton for thrownsnowball Program To determine if the program operates correctly, one must test the program for a representative set of test cases. Test for a fairly simple case that can be verified in your head first then test for the other cases. For the thrownsnowball program, one representative set of test cases is: a hit where the distance is small (< 0 feet), a hit for a distance of around 0 50 feet, a miss where snowball comes up short, and a miss where the snowball flies over the target s head. Some sample results for the thrownsnowball program are: Height thrower 6 feet, height target 5.5 feet, distance to target 0 feet, snowball velocity 50 fps, and snowball angle 0 degrees. This is a hit, height of snowball at the target is 5.34 feet. fps, and snowball angle 0 degrees. This is a miss, height of snowball at the target is 5.6 feet. The snowball flew just over the target. fps, and snowball angle 0 degrees. This is a miss, height of snowball at the target is -. feet. The snowball fell short. fps, and snowball angle 5 degrees. This is a hit, height of snowball at the target is.8 feet. Height thrower 6 feet, height target 5.5 feet, distance to target 50 feet, snowball velocity 00 fps, and snowball angle 0 degrees. This is a miss, height of snowball at the target is 0.6 feet. The snowball flew well over the target. 4

Note: 50 fps is 34. mph and 00 fps is 68. mph. clear all; clc; close all; % gravity gx = 0.0; gy = -3.8; % ft/s^ % Initial position of thrower sx0 = 0; % ft sy0 = input('enter height of snowball thrower in ft: '); % Horizontal and vertical distance to the target sx = input('enter horizontal distance to the target in ft: '); height = input('enter height of target in ft: '); % Initial velocity and release angle of the snowball v0 = input('enter initial velocity of snowball in ft/s: '); theta = input('enter release angle of snowball in degrees: '); % Determine if snowball hit target % Calculate the x and y components of the snowball s velocity vx0 = v0*cosd(theta); vy0 = v0*sind(theta); % Calculate the time it takes the snowball to reach the target ttarget = sx/vx0; % Calculate the height of the snowball when it reaches target sy = sy0 + vy0*ttarget + 0.5*gy*ttarget^; % Determine if snowball height is less than the target height if (sy > 0.0 && sy < height) message = 'Snowball hit target'; else message = 'Snowball missed target'; end % Output whether snowball hit target. disp(message); Figure b, thrownsnowball Program (Omitting Program Comment Header) Last modified Tuesday, September 09, 04 This work by Thomas Murphy is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License. 5