Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a MATLAB function called FUNC1_4.m which starts with the following line: function CFUNC1_4 (A, B,option) This function will take inputs A and B (vectors
Create a MATLAB function called FUNC1_4.m which starts with the following line: function CFUNC1_4 (A, B,option) This function will take inputs A and B (vectors or matrices of any size) and option (scalar number from 1 to 3) and create the output matrix C, where C -A + B, if option= 1, C -A . * B, if option-2, C-AB, if option 3 However, this isn't quite as easy at it sounds because you must follow the following two rules: 1. You can NOT use vectorized MATLAB operations, like A+B, A.*B, A*B as shown above, which do all the additions and multiplication in one command. You MUST use multiple, nested for loops to break the problem down into the individual multiplications and/or additions performed on just one pair of scalar numbers from A and B at a time (sort of like how we first calculated the cannon-ball energies in Class 2) 2. You must check at the beginning of the function that the input matrices A and B have consistent sizes (depending on the value of option) to allow for a mathematically valid C For example, if option = 2 then A and B must have identical size (since A* B only makes sense if A and B have the same size), but if option 3 then there's a different requirement on the relative size between A and B to ensure A*B makes sense If you detect an inconsistency in the size of A and B, such that C can not be validly evaluated, then have your function indicate that by setting C -'No good! Garbage.'instead of calculating an actual value for C. Finally, it's OK to assume that A and B will never be scalars, but rather true vectors or matrices, where at least one of the dimensions is greater than 1. Be sure to test your function out to make sure it works
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started