command s answer 4 4 write a function that accepts an
play

Command(s) Answer 4. 4. Write a function that accepts an array A in - PDF document

UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN COMP CO MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT CPE0907311 COMPUTER CPE0907311 COMPUTER APPLICATIONS LAB APPLICATIONS LAB EXERCISE SHEET 5 EXERC SE SHEET 5 STUDY THE S


  1. UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN COMP CO MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT CPE0907311 COMPUTER CPE0907311 COMPUTER APPLICATIONS LAB APPLICATIONS LAB EXERCISE SHEET 5 EXERC SE SHEET 5 STUDY THE S STUD Y THE SLIDES O IDES OF EXPERI EXPERIMENT 5 MENT 5 AND SOLV AND SOLVE THE FO E THE FOLLOW LLOWING ING PROB PROBLEMS LEMS BEFORE COMING TO THE LAB. BEFORE COMING TO THE LAB. 1. 1. Find the results of the following expressions by hand then use Matlab to check your results. Expression Answer Z = Z = 12 > 5 - 8 Z = Z = 6 + 3 > 18 Z = 5 <= (2*2) Z = 2. 2. Suppose that x = [10,-3,19,12] and y = [3,1,-1,-3]. Evaluate the following expressions by hand then verify your answer by Matlab. Provide a brief explanation for each case. Expression Answer Z = Z = (x < 6) Z = Z = (x~=y) Z = (y<~x) Z = Z = x|y Z = 3. 3. Given the arrays x and y in problem 2, use Matlab to find the indices of elements in y that are greater or equal than their corresponding elements in array x. Then, use array addressing to extract the values of these elements. Command(s) Answer 4. 4. Write a function that accepts an array A in its arguments and returns the array B that is computed from array A such that: a. Elements in A less than or equal to -2 are replaced by 30. b. Elements in A greater than -2 and less than 5 are replaced by 15. c. Elements greater than 5 are replaced by 5. Test your function with ⎡ ⎤ 2 5 10 ⎢ ⎥ = − − A 8 1 11 ⎢ ⎥ ⎢ ⎥ − ⎣ 43 6 2 ⎦ 1 1 Prepared by Dr. Iyad Jafar

  2. UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN COMP CO MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT CPE0907311 COMPUTER CPE0907311 COMPUTER APPLICATIONS LAB APPLICATIONS LAB EXERC EXERCISE SHEET 5 SE SHEET 5 Program using a for loop Program using array masking Array B computed from A above 5. 5. The height and speed of a projectile launched with a speed of v0 at an angle A to the horizontal are given by = − 2 ( ) sin 0.5 h t v t A gt 0 2 = − + 2 2 ( ) 2 sin v t v v gt A g t 0 0 Where g is the acceleration due to gravity. The projectile will strike the ground when h(t) – 0, which gives the time to hit t hit = 2(v 0 /g) sin A. Write a Matlab program that uses the switch statement to compute either the maximum height reached by the projectile, the total horizontal distance traveled, or the time to hit. The program should accept as input the user’s choice of which quantity to compute and the values of v 0 , A, and g. Test the program for the case when v 0 = 40 m/s, A=30 o , and g = 9.81 m/s 2 . 2 2 Prepared by Dr. Iyad Jafar

  3. UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN COMP CO MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT CPE0907311 COMPUTER APPLICATIONS LAB CPE0907311 COMPUTER APPLICATIONS LAB EXERCISE SHEET 5 EXERC SE SHEET 5 Program Code 6. Solve problems 10, 14, 20, 33, and 35 from chapter 4 in the book. 6. 3 3 Prepared by Dr. Iyad Jafar

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend