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

command s answer 4 4 write a function that accepts an
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

CPE0907311 COMPUTER CPE0907311 COMPUTER APPLICATIONS LAB APPLICATIONS LAB EXERC EXERCISE SHEET 5 SE SHEET 5

1 1

UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN CO COMP MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT

Prepared by Dr. Iyad Jafar

STUD STUDY THE S 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 = 12 > 5 - 8

Z =

Z = 6 + 3 > 18

Z =

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 = (x < 6)

Z =

Z = (x~=y)

Z =

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 ⎡ ⎤ ⎢ ⎥ = − − ⎢ ⎥ ⎢ ⎥ − ⎣ ⎦

slide-2
SLIDE 2

CPE0907311 COMPUTER CPE0907311 COMPUTER APPLICATIONS LAB APPLICATIONS LAB EXERC EXERCISE SHEET 5 SE SHEET 5

2 2

UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN CO COMP MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT

Prepared by Dr. Iyad Jafar

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 = −

2 2

( ) 2 sin v t v v gt A g t = − +

2

Where g is the acceleration due to gravity. The projectile will strike the ground when h(t) – 0, which gives the time to hit thit = 2(v0/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

  • f v0, A, and g. Test the program for the case when v0 = 40 m/s, A=30o, and g = 9.81 m/s2.
slide-3
SLIDE 3

CPE0907311 COMPUTER CPE0907311 COMPUTER APPLICATIONS LAB APPLICATIONS LAB EXERC EXERCISE SHEET 5 SE SHEET 5

3 3

UNIVERSITY OF JORDAN UNIVERSITY OF JORDAN CO COMP MPUTER ENGI UTER ENGINEERIN NEERING DEPARTM G DEPARTMENT NT

Prepared by Dr. Iyad Jafar

Program Code

6.

  • 6. Solve problems 10, 14, 20, 33, and 35 from chapter 4 in the book.