MATH 251 - Introduction to MATLAB



Similar documents
Chapter 4 - Practice Problems 2

GeoGebra. 10 lessons. Gerrit Stols

Projectile motion simulator.

Maximum Range Explained range Figure 1 Figure 1: Trajectory Plot for Angled-Launched Projectiles Table 1

10.1. Solving Quadratic Equations. Investigation: Rocket Science CONDENSED

1 of 7 9/5/2009 6:12 PM

Chapter 1: Looking at Data Section 1.1: Displaying Distributions with Graphs

How To Factor By Gcf In Algebra 1.5

Evaluating Statements About Probability

Mathematics Placement Examination (MPE)

Newton s Second Law. ΣF = m a. (1) In this equation, ΣF is the sum of the forces acting on an object, m is the mass of

Exploratory data analysis (Chapter 2) Fall 2011

Exam 1 Review Questions PHY Exam 1

Algebra II EOC Practice Test

BNG 202 Biomechanics Lab. Descriptive statistics and probability distributions I

Definition: A vector is a directed line segment that has and. Each vector has an initial point and a terminal point.

Gerrit Stols

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

Projectile Motion 1:Horizontally Launched Projectiles

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION INTEGRATED ALGEBRA. Tuesday, January 27, :15 to 4:15 p.m.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Algebra I Vocabulary Cards

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION MATHEMATICS B. Thursday, January 29, :15 a.m. to 12:15 p.m.

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION INTEGRATED ALGEBRA. Thursday, August 16, :30 to 11:30 a.m.

Glencoe. correlated to SOUTH CAROLINA MATH CURRICULUM STANDARDS GRADE 6 3-3, , , 4-9

Mechanics 1: Conservation of Energy and Momentum

Algebra EOC Practice Test #4

Lab #4 - Linear Impulse and Momentum

Variables. Exploratory Data Analysis

McDougal Littell California:

Biggar High School Mathematics Department. National 5 Learning Intentions & Success Criteria: Assessing My Progress

Numerical integration of a function known only through data points

Pre-Algebra Academic Content Standards Grade Eight Ohio. Number, Number Sense and Operations Standard. Number and Number Systems

Figure 1.1 Vector A and Vector F

of surface, , , of triangle, 548 Associative Property of addition, 12, 331 of multiplication, 18, 433

Tutorial 3: Graphics and Exploratory Data Analysis in R Jason Pienaar and Tom Miller

Common Core State Standards for Mathematics Accelerated 7th Grade

Physics Kinematics Model

Quick Tour of Mathcad and Examples

6. Vectors Scott Surgent (surgent@asu.edu)

Open-Ended Problem-Solving Projections

Chapter 3 Practice Test

4. How many integers between 2004 and 4002 are perfect squares?

Bridging Documents for Mathematics

Engineering Problem Solving and Excel. EGN 1006 Introduction to Engineering

Web review - Ch 3 motion in two dimensions practice test

Chapter 3 Falling Objects and Projectile Motion

Slope and Rate of Change

x 2 + y 2 = 1 y 1 = x 2 + 2x y = x 2 + 2x + 1

Chapter 8 Geometry We will discuss following concepts in this chapter.

Physics 2048 Test 1 Solution (solutions to problems 2-5 are from student papers) Problem 1 (Short Answer: 20 points)

KE =? v o. Page 1 of 12

Data Mining: Algorithms and Applications Matrix Math Review

MATH 100 PRACTICE FINAL EXAM

APPLIED MATHEMATICS ADVANCED LEVEL

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION INTEGRATED ALGEBRA. Wednesday, June 12, :15 to 4:15 p.m.

Polynomial Degree and Finite Differences

a. all of the above b. none of the above c. B, C, D, and F d. C, D, F e. C only f. C and F

MATH 095, College Prep Mathematics: Unit Coverage Pre-algebra topics (arithmetic skills) offered through BSE (Basic Skills Education)

The right edge of the box is the third quartile, Q 3, which is the median of the data values above the median. Maximum Median

Number Sense and Operations

DesCartes (Combined) Subject: Mathematics Goal: Statistics and Probability

Descriptive Statistics

Math 115 Extra Problems for 5.5

SECTION 1-6 Quadratic Equations and Applications

Solutions to old Exam 1 problems

TI-Nspire CAS Graphing Calculator

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION MATHEMATICS A. Monday, January 27, :15 to 4:15 p.m.

Microsoft Excel Tutorial

Mental Questions. Day What number is five cubed? 2. A circle has radius r. What is the formula for the area of the circle?

ALGEBRA I (Common Core) Tuesday, June 3, :15 a.m. to 12:15 p.m., only

Bar Graphs and Dot Plots

FREE FALL. Introduction. Reference Young and Freedman, University Physics, 12 th Edition: Chapter 2, section 2.5

SAT Math Facts & Formulas Review Quiz

ALGEBRA 2/TRIGONOMETRY

4.1 INTRODUCTION TO THE FAMILY OF EXPONENTIAL FUNCTIONS

1 Introduction to Matrices

First Midterm Exam (MATH1070 Spring 2012)

Combinatorics. Chapter Factorials

04 Mathematics CO-SG-FLD Program for Licensing Assessments for Colorado Educators

W i f(x i ) x. i=1. f(x i ) x = i=1

WEDNESDAY, 2 MAY 1.30 PM 2.25 PM. 3 Full credit will be given only where the solution contains appropriate working.

with functions, expressions and equations which follow in units 3 and 4.

Scope and Sequence KA KB 1A 1B 2A 2B 3A 3B 4A 4B 5A 5B 6A 6B

ALGEBRA I (Common Core) Wednesday, August 13, :30 to 11:30 a.m., only

Solving Quadratic Equations

Statistics Revision Sheet Question 6 of Paper 2

Math 120 Final Exam Practice Problems, Form: A

CURVE FITTING LEAST SQUARES APPROXIMATION

AP Statistics Solutions to Packet 2

Summary of Formulas and Concepts. Descriptive Statistics (Ch. 1-4)

Florida Math for College Readiness

MA107 Precalculus Algebra Exam 2 Review Solutions

Experiment 2 Free Fall and Projectile Motion

Answer Key for California State Standards: Algebra I

MAT12X Intermediate Algebra

4.3 Lagrange Approximation

ALPERTON COMMUNITY SCHOOL MATHS FACULTY ACHIEVING GRADE A/A* EXAM PRACTICE BY TOPIC

Common Core Unit Summary Grades 6 to 8

Chapter 111. Texas Essential Knowledge and Skills for Mathematics. Subchapter B. Middle School

Transcription:

KINGDOM OF SAUDI ARABIA - AL-IMAM MUHAMMAD BIN SAUD ISLAMIC UNIVERSITY - FACULTY OF SCIENCES - - May 9, 2011 Semester 2, 1431-1432 (2010-20111) MATH 251 - Introduction to MATLAB Exercise sheet 6 Dr. Samy MZIOU Exercise 1 : 1. Write a function file R = RECTANGLE(a, b) which compute the area of a rectangle with length a and width b. 2. Write a function file which compute the area of a trapezoid. 3. Write a function that compute the maximum of a vector V ECT Exercise 2 : 6.10 EXAMPLES OF MATLAB APPLICATIONS Sample Problem 6-4: Exponential growth and decay A model for exponential growth, or decay, of a quantity is given by: A(t) = A 0 e kt where A{t) and A 0 are the quantity at time t and time 0, respectively, and k is a constant unique to the specific application. Write a user-defined function that uses this model to predict the quantity A(t) at time t from knowing A 0 and A{t x ) at some other time t v For function name and arguments use At = expgd (A0, A t l, t l, t ), where the output argument At corresponds to A(t), and the input arguments A 0, A t l, t l, t corresponds to AQ, A(t x ), t x, and t, respectively. Use the function file in the Command Window for the following two cases: a) The population of Mexico was 67 millions in the year 1980 and 79 million in 1986. Estimate the population in 2000. b) The half-life of a radioactive material is 5.8 years. How much of a 7-gram sample will be left after 30 years. Solution 1

Sample Problem 6-5: Motion of a Projectile Create a function file that calculates the trajectory of a projectile. The inputs to the function are the initial velocity and the angle at which the projectile is fired. The outputs h \ from the function are the maximum height " max ^ " ^ and distance. In addition, the function generates a plot of the trajectory. Use the function to calculate the trajectory of a projectile that is fired at a velocity of 230 m/s at an angle of 39. Solution The motion of a projectile can be analyzed by considering the horizontal and vertical components. The initial velocity v 0 can be resolved into horizontal and vertical components: v ox = v 0 cos(9) and v Qy = v o sin(0) In the vertical direction the velocity and position of the projectile are given by: v y = v 0y -gt and y = v 0y t--gt 2 The time it takes the projectile to reach the highest point (v^ = 0) and the corresponding height are given by: t, = v Ji and h = ^z ''hmax akxyx "max n The total flying time is twice the time it takes the projectile to reach the highest point, t tot = 2t hmax. In the horizontal direction the velocity is constant, and the position of the projectile is given by: x = v 0x t In MATLAB notation the function name and arguments are taken as: [hmax, dmax] = t r a j e c t o r y (vo, t h e t a ). The function file is: Exercise 3 : Problem 7-2: Calculating worker s pay A worker is paid according to his hourly wage up to 40 hours, and 50 % more for overtime. Write a program in a script file that calculates the pay to a worker. The program asks the user to enter the number of hours and the hourly wage. The program then displays the pay. Exercise 4 : Problem 7-4: Converting units of energy Write a program in a script file that converts a quantity of energy (work) given in units of either Joule, ft-lb, cal, or ev to the equivalent quantity in different units specified by the user. The program asks the user to enter the quantity of energy, its current units, and the new desired units. The output is the quantity of energy in the new units. The conversion factors are: 1 J = 0.738 ft-lb = 0.239 cal = 6.24 10 18 ev. Use the program to: a) Convert 150 J to ft-lb. b) 2800 cal to Joules. c) 2.7 ev to cal. 2

Sample Problem 7-3: Water level in water tower The tank in a water tower has the geometry shown in the figure (the lower part is a cylinder and the upper part is an inverted frustum cone). 14 m Inside the tank there is a float that indicates the level of the water. Write a user-defined function t file that determines the volume of the water in 19m the tank from the position (height h) of the float. The input to the function is the value of h in m, and the output is the volume of the water in m3. 1 diameter 46 m _E : diameter 25 m Solution Sample Problem 7-5: Sum of series a) Use a f o r - end loop in a script file to calculate the sum of the first n terms of ^ i (_i )kk the series: 2^ jr~ Execute the script file for n = 4 and n = 20. *=i ^ b) The function sin(x) can be written as a Taylor series by: smr = > i -1 OJr-i- 1 V Write a user-defined function file that calculates sin(x) by using the Taylor's series. For the function name and arguments use y = T s i n ( x / n ). The input arguments are the angle x in degrees, and n the number of terms in the series. Use the function to calculate sin(150 ) using 3 and 7 terms. Solution Sample Problem 7-6: Modify vector elements A vector is given by: V= [5, 17, - 3, 8, 0, - 1, 12, 15, 20, -6, 6, 4, - 7, 16]. Write a program as a script file that doubles the elements that are positive and are divisible by 3 and/or 5, and raise to the power of 3 the elements that are negative but greater than-5. Sample Problem 7-8: Creating a matrix with a loop Write a program in a script file that creates a n x m matrix with elements that have the following values. The value of the elements in the first row is the number of the column. The value of the element in the first column is the number of the row. The rest of the elements are equal to the sum of the element above them and the element to the left. When executed, the program asks the user to enter values for n and m. Sample Problem 7-11: Flight of a model rocket The flight of a model rocket can be modeled as follows. During the first 0.15 s the rocket is propelled up by the rocket engine with a force of 16N. The rocket then flies up while slowing down under the force of gravity. After it reaches the apex, the rocket starts to fall back down. When its down velocity reaches 20 m/s a parachute opens (assumed to open instantly) and the rocket continues to move down at a constant speed of 20 m/s until it hits the ground. Write a program that calculates and plots the speed and altitude of the rocket as a function of time during the flight. Solution 3

Exercise 5 : linear algebra let A = [2, 5, 1; 0, 3, 1]; B = [1, 0, 2; 1, 4, 2; 5, 2, 1] 1. Compute AB 2. Compute BA. explain what happens. 3. Compute the transpose of A Exercise 6 : linear algebra Consider the following linear system 1. Write the system using matrix notation 3x + 2y z = 10 x + 3y + 2z = 5 x y z = 1 2. Solve the system using inv MATLAB command 3. Solve the system using the MATLAB operator \ Exercise 7 : Interpolation Let the following table of points 1 2 3 4 5 6 0 20 55 65 100 120 Find the interpolating polynomial using the MATLAB function interp1 Exercise 8 : Polynomials evaluation let the polynomial p(x) = x 5 12.1x 4 + 40.59x 3 17.01x 2 71.95x + 35.88, 1. Calculate p(9) using the MATLAB function polyval 2. Plot the polynomial for 1.5 x 6.7 3. Compute the roots of p using the MATLAB function roots Exercise 9 : Integration and differentiation 1. Using MATLAB function quad compute the integral of f(x) = 1 1+x 2 over [0, 1]. Compare with the analytical solution. 2. Compute the integral of f(x) = 1 1+x 5 over [0, 2]. 4

KINGDOM OF SAUDI ARABIA - AL-IMAM MUHAMMAD BIN SAUD ISLAMIC UNIVERSITY - FACULTY OF SCIENCES - - May 9, 2011 Semester 2, 1431-1432 (2010-20111) MATH 251 - Introduction to MATLAB Exercise sheet 6 Dr. Samy MZIOU Exercise 1 : 1. Write a function file R = RECTANGLE(a, b) which compute the area of a rectangle with length a and width b. 2. Write a function file which compute the area of a trapezoid. 3. Write a function that compute the maximum of a vector V ECT Exercise 2 : 6.10 EXAMPLES OF MATLAB APPLICATIONS Sample Problem 6-4: Exponential growth and decay A model for exponential growth, or decay, of a quantity is given by: A(t) = A 0 e kt where A{t) and A 0 are the quantity at time t and time 0, respectively, and k is a constant unique to the specific application. Write a user-defined function that uses this model to predict the quantity A(t) at time t from knowing A 0 and A{t x ) at some other time t v For function name and arguments use At = expgd (A0, A t l, t l, t ), where the output argument At corresponds to A(t), and the input arguments A 0, A t l, t l, t corresponds to AQ, A(t x ), t x, and t, respectively. Use the function file in the Command Window for the following two cases: a) The population of Mexico was 67 millions in the year 1980 and 79 million in 1986. Estimate the population in 2000. b) The half-life of a radioactive material is 5.8 years. How much of a 7-gram sample will be left after 30 years. Solution 1

Sample Problem 6-5: Motion of a Projectile Create a function file that calculates the trajectory of a projectile. The inputs to the function are the initial velocity and the angle at which the projectile is fired. The outputs h \ from the function are the maximum height " max ^ " ^ and distance. In addition, the function generates a plot of the trajectory. Use the function to calculate the trajectory of a projectile that is fired at a velocity of 230 m/s at an angle of 39. Solution The motion of a projectile can be analyzed by considering the horizontal and vertical components. The initial velocity v 0 can be resolved into horizontal and vertical components: v ox = v 0 cos(9) and v Qy = v o sin(0) In the vertical direction the velocity and position of the projectile are given by: v y = v 0y -gt and y = v 0y t--gt 2 The time it takes the projectile to reach the highest point (v^ = 0) and the corresponding height are given by: t, = v Ji and h = ^z ''hmax akxyx "max n The total flying time is twice the time it takes the projectile to reach the highest point, t tot = 2t hmax. In the horizontal direction the velocity is constant, and the position of the projectile is given by: x = v 0x t In MATLAB notation the function name and arguments are taken as: [hmax, dmax] = t r a j e c t o r y (vo, t h e t a ). The function file is: Exercise 3 : Problem 7-2: Calculating worker s pay A worker is paid according to his hourly wage up to 40 hours, and 50 % more for overtime. Write a program in a script file that calculates the pay to a worker. The program asks the user to enter the number of hours and the hourly wage. The program then displays the pay. Exercise 4 : Problem 7-4: Converting units of energy Write a program in a script file that converts a quantity of energy (work) given in units of either Joule, ft-lb, cal, or ev to the equivalent quantity in different units specified by the user. The program asks the user to enter the quantity of energy, its current units, and the new desired units. The output is the quantity of energy in the new units. The conversion factors are: 1 J = 0.738 ft-lb = 0.239 cal = 6.24 10 18 ev. Use the program to: a) Convert 150 J to ft-lb. b) 2800 cal to Joules. c) 2.7 ev to cal. 2

Sample Problem 7-3: Water level in water tower The tank in a water tower has the geometry shown in the figure (the lower part is a cylinder and the upper part is an inverted frustum cone). 14 m Inside the tank there is a float that indicates the level of the water. Write a user-defined function t file that determines the volume of the water in 19m the tank from the position (height h) of the float. The input to the function is the value of h in m, and the output is the volume of the water in m3. 1 diameter 46 m _E : diameter 25 m Solution Sample Problem 7-5: Sum of series a) Use a f o r - end loop in a script file to calculate the sum of the first n terms of ^ i (_i )kk the series: 2^ jr~ Execute the script file for n = 4 and n = 20. *=i ^ b) The function sin(x) can be written as a Taylor series by: smr = > i -1 OJr-i- 1 V Write a user-defined function file that calculates sin(x) by using the Taylor's series. For the function name and arguments use y = T s i n ( x / n ). The input arguments are the angle x in degrees, and n the number of terms in the series. Use the function to calculate sin(150 ) using 3 and 7 terms. Solution Sample Problem 7-6: Modify vector elements A vector is given by: V= [5, 17, - 3, 8, 0, - 1, 12, 15, 20, -6, 6, 4, - 7, 16]. Write a program as a script file that doubles the elements that are positive and are divisible by 3 and/or 5, and raise to the power of 3 the elements that are negative but greater than-5. Sample Problem 7-8: Creating a matrix with a loop Write a program in a script file that creates a n x m matrix with elements that have the following values. The value of the elements in the first row is the number of the column. The value of the element in the first column is the number of the row. The rest of the elements are equal to the sum of the element above them and the element to the left. When executed, the program asks the user to enter values for n and m. Sample Problem 7-11: Flight of a model rocket The flight of a model rocket can be modeled as follows. During the first 0.15 s the rocket is propelled up by the rocket engine with a force of 16N. The rocket then flies up while slowing down under the force of gravity. After it reaches the apex, the rocket starts to fall back down. When its down velocity reaches 20 m/s a parachute opens (assumed to open instantly) and the rocket continues to move down at a constant speed of 20 m/s until it hits the ground. Write a program that calculates and plots the speed and altitude of the rocket as a function of time during the flight. Solution 3

Exercise 5 : linear algebra let A = [2, 5, 1; 0, 3, 1]; B = [1, 0, 2; 1, 4, 2; 5, 2, 1] 1. Compute AB 2. Compute BA. explain what happens. 3. Compute the transpose of A Exercise 6 : linear algebra Consider the following linear system 1. Write the system using matrix notation 3x + 2y z = 10 x + 3y + 2z = 5 x y z = 1 2. Solve the system using inv MATLAB command 3. Solve the system using the MATLAB operator \ Exercise 7 : Interpolation Let the following table of points 1 2 3 4 5 6 0 20 55 65 100 120 Find the interpolating polynomial using the MATLAB function interp1 Exercise 8 : Polynomials evaluation let the polynomial p(x) = x 5 12.1x 4 + 40.59x 3 17.01x 2 71.95x + 35.88, 1. Calculate p(9) using the MATLAB function polyval 2. Plot the polynomial for 1.5 x 6.7 3. Compute the roots of p using the MATLAB function roots Exercise 9 : Integration and differentiation 1. Using MATLAB function quad compute the integral of f(x) = 1 1+x 2 over [0, 1]. Compare with the analytical solution. 2. Compute the integral of f(x) = 1 1+x 5 over [0, 2]. 4

KINGDOM OF SAUDI ARABIA - AL-IMAM MUHAMMAD BIN SAUD ISLAMIC UNIVERSITY - FACULTY OF SCIENCES - - May 9, 2011 Semester 2, 1431-1432 (2010-20111) MATH 251 - Introduction to MATLAB Exercise sheet 6 Dr. Samy MZIOU Exercise 1 : 1. Write a function file R = RECTANGLE(a, b) which compute the area of a rectangle with length a and width b. 2. Write a function file which compute the area of a trapezoid. 3. Write a function that compute the maximum of a vector V ECT Exercise 2 : 6.10 EXAMPLES OF MATLAB APPLICATIONS Sample Problem 6-4: Exponential growth and decay A model for exponential growth, or decay, of a quantity is given by: A(t) = A 0 e kt where A{t) and A 0 are the quantity at time t and time 0, respectively, and k is a constant unique to the specific application. Write a user-defined function that uses this model to predict the quantity A(t) at time t from knowing A 0 and A{t x ) at some other time t v For function name and arguments use At = expgd (A0, A t l, t l, t ), where the output argument At corresponds to A(t), and the input arguments A 0, A t l, t l, t corresponds to AQ, A(t x ), t x, and t, respectively. Use the function file in the Command Window for the following two cases: a) The population of Mexico was 67 millions in the year 1980 and 79 million in 1986. Estimate the population in 2000. b) The half-life of a radioactive material is 5.8 years. How much of a 7-gram sample will be left after 30 years. Solution 1

Sample Problem 6-5: Motion of a Projectile Create a function file that calculates the trajectory of a projectile. The inputs to the function are the initial velocity and the angle at which the projectile is fired. The outputs h \ from the function are the maximum height " max ^ " ^ and distance. In addition, the function generates a plot of the trajectory. Use the function to calculate the trajectory of a projectile that is fired at a velocity of 230 m/s at an angle of 39. Solution The motion of a projectile can be analyzed by considering the horizontal and vertical components. The initial velocity v 0 can be resolved into horizontal and vertical components: v ox = v 0 cos(9) and v Qy = v o sin(0) In the vertical direction the velocity and position of the projectile are given by: v y = v 0y -gt and y = v 0y t--gt 2 The time it takes the projectile to reach the highest point (v^ = 0) and the corresponding height are given by: t, = v Ji and h = ^z ''hmax akxyx "max n The total flying time is twice the time it takes the projectile to reach the highest point, t tot = 2t hmax. In the horizontal direction the velocity is constant, and the position of the projectile is given by: x = v 0x t In MATLAB notation the function name and arguments are taken as: [hmax, dmax] = t r a j e c t o r y (vo, t h e t a ). The function file is: Exercise 3 : Problem 7-2: Calculating worker s pay A worker is paid according to his hourly wage up to 40 hours, and 50 % more for overtime. Write a program in a script file that calculates the pay to a worker. The program asks the user to enter the number of hours and the hourly wage. The program then displays the pay. Exercise 4 : Problem 7-4: Converting units of energy Write a program in a script file that converts a quantity of energy (work) given in units of either Joule, ft-lb, cal, or ev to the equivalent quantity in different units specified by the user. The program asks the user to enter the quantity of energy, its current units, and the new desired units. The output is the quantity of energy in the new units. The conversion factors are: 1 J = 0.738 ft-lb = 0.239 cal = 6.24 10 18 ev. Use the program to: a) Convert 150 J to ft-lb. b) 2800 cal to Joules. c) 2.7 ev to cal. 2

Sample Problem 7-3: Water level in water tower The tank in a water tower has the geometry shown in the figure (the lower part is a cylinder and the upper part is an inverted frustum cone). 14 m Inside the tank there is a float that indicates the level of the water. Write a user-defined function t file that determines the volume of the water in 19m the tank from the position (height h) of the float. The input to the function is the value of h in m, and the output is the volume of the water in m3. 1 diameter 46 m _E : diameter 25 m Solution Sample Problem 7-5: Sum of series a) Use a f o r - end loop in a script file to calculate the sum of the first n terms of ^ i (_i )kk the series: 2^ jr~ Execute the script file for n = 4 and n = 20. *=i ^ b) The function sin(x) can be written as a Taylor series by: smr = > i -1 OJr-i- 1 V Write a user-defined function file that calculates sin(x) by using the Taylor's series. For the function name and arguments use y = T s i n ( x / n ). The input arguments are the angle x in degrees, and n the number of terms in the series. Use the function to calculate sin(150 ) using 3 and 7 terms. Solution Sample Problem 7-6: Modify vector elements A vector is given by: V= [5, 17, - 3, 8, 0, - 1, 12, 15, 20, -6, 6, 4, - 7, 16]. Write a program as a script file that doubles the elements that are positive and are divisible by 3 and/or 5, and raise to the power of 3 the elements that are negative but greater than-5. Sample Problem 7-8: Creating a matrix with a loop Write a program in a script file that creates a n x m matrix with elements that have the following values. The value of the elements in the first row is the number of the column. The value of the element in the first column is the number of the row. The rest of the elements are equal to the sum of the element above them and the element to the left. When executed, the program asks the user to enter values for n and m. Sample Problem 7-11: Flight of a model rocket The flight of a model rocket can be modeled as follows. During the first 0.15 s the rocket is propelled up by the rocket engine with a force of 16N. The rocket then flies up while slowing down under the force of gravity. After it reaches the apex, the rocket starts to fall back down. When its down velocity reaches 20 m/s a parachute opens (assumed to open instantly) and the rocket continues to move down at a constant speed of 20 m/s until it hits the ground. Write a program that calculates and plots the speed and altitude of the rocket as a function of time during the flight. Solution 3

Exercise 5 : linear algebra let A = [2, 5, 1; 0, 3, 1]; B = [1, 0, 2; 1, 4, 2; 5, 2, 1] 1. Compute AB 2. Compute BA. explain what happens. 3. Compute the transpose of A Exercise 6 : linear algebra Consider the following linear system 1. Write the system using matrix notation 3x + 2y z = 10 x + 3y + 2z = 5 x y z = 1 2. Solve the system using inv MATLAB command 3. Solve the system using the MATLAB operator \ Exercise 7 : Interpolation Let the following table of points 1 2 3 4 5 6 0 20 55 65 100 120 Find the interpolating polynomial using the MATLAB function interp1 Exercise 8 : Polynomials evaluation let the polynomial p(x) = x 5 12.1x 4 + 40.59x 3 17.01x 2 71.95x + 35.88, 1. Calculate p(9) using the MATLAB function polyval 2. Plot the polynomial for 1.5 x 6.7 3. Compute the roots of p using the MATLAB function roots Exercise 9 : Integration and differentiation 1. Using MATLAB function quad compute the integral of f(x) = 1 1+x 2 over [0, 1]. Compare with the analytical solution. 2. Compute the integral of f(x) = 1 1+x 5 over [0, 2]. 4

KINGDOOM OF SAUDI ARABIA Al-Imam Muhammad Ibn Saud Islamic University Faculty of Sciences Name Section Student ID Quiz 1 - SOLUTION 8 37 13 24 9 45 23 1 36 18 33 10 12 24 20 22 30 24 47 24 44 1. Construct a stem and leaf plot from the above data. Answer: 1 8 9 10 11 13 18 20 22 22 24 24 24 24 30 36 36 37 44 45 47 Stem Leaf 0 1 8 9 1 0 1 3 8 2 0 2 2 4 4 4 4 3 0 6 6 7 4 4 5 7 Dr. A. S. BEN GHORBAL Page 1

KINGDOOM OF SAUDI ARABIA Al-Imam Muhammad Ibn Saud Islamic University Faculty of Sciences 2. Calculate the mean, mode and the quartiles of the data. Answer: Mode = 24 Median = 24 Mean = 504 / 21 = 24 Quartile 1 = 12 Quartile 2 = Median = 24 Quartile 3 = 36 Interquartile range (IQR) = 36 12 = 24 Upper inner fences = Q3 + 1.5 * IQR = 36 + (1.5 * 24) = 36 + 36 = 72 Lower inner fences = Q1 (1.5 * IQR) = 12 - (1.5 * 24) = 12 36 = - 24 Dr. A. S. BEN GHORBAL Page 2

KINGDOOM OF SAUDI ARABIA Al-Imam Muhammad Ibn Saud Islamic University Faculty of Sciences Name Section Student ID Quiz 1 - SOLUTION 8 36 10 2 7 13 17 2 15 28 0 12 1 29 9 29 49 16 2 28 2 1. Construct a stem and leaf plot from the above data. Answer: 0 1 2 2 2 2 7 8 9 10 12 13 15 16 17 28 28 29 29 36 49 Stem Leaf 0 0 1 2 2 2 2 7 8 9 1 0 2 3 5 6 7 2 8 8 9 9 3 6 4 9 2. Calculate the mean, mode and the quartiles of the data. Dr. A. S. BEN GHORBAL Page 1

KINGDOOM OF SAUDI ARABIA Al-Imam Muhammad Ibn Saud Islamic University Faculty of Sciences Answer: Mode = 2 Median = 12 Mean = 315 / 21 = 15 Quartile 1 = 2 Quartile 2 = Median = 12 Quartile 3 = 28 Interquartile range (IQR) = 28 2 = 26 Upper inner fences = Q3 + 1.5 * IQR = 28 + (1.5 * 26) = 28 + 39 = 67 Lower inner fences = Q1-1.5 * IQR = 2 - (1.5 * 26) = 2 39 = - 37 Dr. A. S. BEN GHORBAL Page 2

KINGDOOM OF SAUDI ARABIA Al-Imam Muhammad Ibn Saud Islamic University Faculty of Sciences MATH 301 - QUIZ 02 Saturday, December 01, 2007 Section: 171 SOLUTION PROBLEM [5 POINTS] Four fair coins are tossed. 1. [1.75 POINT] How many outcomes are in the sample space (list all the elements)? SOLUTION: Denote by S the sample space, so we have,,,, S H T H T H T H T HHHH, HHHT, HHTT, HHTH, HTTT, HTTH, HTHH, HTHT, TTTT, THHH, TTTH, TTHH, THTT, THTH, TTHT, THHT Thus, n(s) = 2 4 = 16. 2. [1.75 POINT] What is the probability that all four turn up heads? SOLUTION: Denote by F the event to get all four turn up heads. Thus, F = {HHHH} and P F 3. [1.50 POINT] Name two events A and B in this sample space where A is a subset of B. Neither of these two events should be the empty event; or the entire sample space, and A and B should not be equal. SOLUTION: Suppose that A is the event that all four turn up heads and B is the event that the first coin turns up head. Then, A HHHH, B 1 16 HHHH, HHHT, HHTT, HHTH, HTTT, HTTH, HTHH, HTHT. It is obvious to check that A is a subset of B.

KINGDOOM OF SAUDI ARABIA Al-Imam Muhammad Ibn Saud Islamic University Faculty of Sciences MATH 301 - QUIZ 02 Sunday, December 02, 2007 Section: 174 SOLUTION PROBLEM [5 POINTS] To monitor the performance of a web server the technician in charge records each day whether the server was operational all day (1) or not (0). The technical also records volume of traffic (none, low, medium, high). Consider an experiment that consists of recording the performance record of the web server on a particular day. One possible outcome for this experiment is (1, none) indicating that the server was operational all day but that there was no traffic. 1. [2 POINTS] Give the sample space (all possible outcomes) for this experiment. SOLUTION: We have S 1,none, 1,low, 1,medium, 1,high 0,none, 0,low, 0,medium, 0,high,. 2. [1.5 POINTS] Let A be the event that that there was no traffic. Give the outcomes in A. SOLUTION: We have 0,none, 1,none A. 3. [1.5 POINTS] Let B be the event that the server was operational all day. Give the outcomes in B. SOLUTION: We have 1,none, 1,low, 1,medium, 1,high B.

KINGDOOM OF SAUDI ARABIA Al-Imam Muhammad Ibn Saud Islamic University Faculty of Sciences MATH 301 SOLUTION QUIZ 03 Tuesday, January 08, 2008 Section: 171, 174 NAME: SIGNATURE: STUDENT ID: PROBLEM [5 POINTS] A company has 4 applicants for 2 positions: 1 woman and 3 men. 1. [2 POINTS] Use a tree diagram to list all the possible assignments to positions (HINT: Label the applicants as M1, M2, M3, and W1; assume an individual may only hold one position). Supposing that all applicants are qualified and that no preference is given for choosing either sex so that all outcomes in 1 are equally-likely, answer the following. SOLUTION: POSITION 1 POSITION 2 SIMPLE EVENTS M1 M2 M3 W1 M2 M3 W1 M1 M3 W1 M1 M2 W1 M1 M2 M3 M1 M2 M1 M3 M1 W1 M2 M1 M2 M3 M2 W1 M3 M1 M3 M2 M3 W1 W1 M1 W1 M2 W1 M3 2. [1.5 POINTS] Find the probability that two males are chosen to fill the 2 positions. SOLUTION: P(two males are chosen) = 6/12 or.5 3. [1.5 POINTS] Find the probability that a male is chosen to fill the first position. SOLUTION: P(a male fills the first position) = 9/12 or.75