Question: (a) Write a function [va, vb, vab] = vectdiv_struct (v, a, b) that takes a vector v of arbitrary length and two numbers a and
(a) Write a function [va, vb, vab] = vectdiv_struct (v, a, b) that takes a vector v of arbitrary length and two numbers a and b as input and that does the following: - aborts if the input v is not a vector OR contains non-integer elements - aborts if the inputs a or b are not scalars OR are not integers - in either case prints an appropriate warning message and does NOT do anything further - in either case the return values should be empty vectors
OTHERWISE uses a for loop and conditional structures to: - find the elements of v that are divisible by a and return them in the vector va - find the elements of v that are divisible by b and return them in the vector vb - find the elements of v that are divisible by a AND b and return them in the vector vab Hint: A number x is an integer if rem(x,1) = 0 and divisible by n if rem(x,n) = 0.
(
b)&(c)
Problem 2 (40 points) (a) Write a function [va vb, vab vect div struct (v, a, b) that takes a vector v of arbitrary length and two numbers a and b as input and that does the following: aborts if the input v is not a vector OR contains non-integer elements aborts if the inputs a or b are not scalars OR are not integers in either case prints an appropriate warning message and does NOT do anything further in either case the return values should be empty vectors OTHERWISE uses a for loop and conditional structures to find the elements of v that are divisible by a and return them in the vector va find the elements of v that are divisible by b and return them in the vector vb find the elements of v that are divisible by a AND b and return them in the vector vab Hint: A number x is an integer if rem (x, 1) 0 and divisible by n if rem (x,n)- 0 (b) Write a function va vb, vab vect div vect (v, a, b) that uses vectorization and relational/logical operators/functions instead of a loop with conditionals to solve (a) (c) Test BOTH of your functions for the following cases: iO -1 13 18 11 13 49 47 39 42 30 a 2, b 3 8 3 4], a 11 iii) v 5 8 3 4], a 2.5 iv) v 5 8 3 4], a [3 51 5 8 3 4], a vi) v 5 8 7 1.5 3 41, a 2, b 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
