Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Matlab Write a function [va, vb, vab] = vectdiv_struct (v, a, b) that takes a vector v of arbitrary length and two numbers a

Using Matlab

image text in transcribed

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 Write a function [va, vb, vab] = vectdiv_vect (v, a, b) that uses vectorization and relational/logical operators/functions instead of a loop with conditionals to solve (a). Test BOTH of your functions for the following cases: v = [-1 13 18 -11 -13 49 -47 -39 42 30], a = 2, b = 3 v = [5 8 -7 -3 4], a = 2, b = 3 v = [5 8 -7 -3 4], a = 2.5, b = 3 v = [5 8 -7 -3 4], a = 2, b = [3 5] v = [5 8 -7; 1 -3 4], a = 2, b = 3 v = [5 8 -7 1.5 -3 4], a = 2, b = 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions