- 5 Write A Function With Header F Mymultoperation A B Operation The Input Argument Operation Is A String That Is 1 (29.79 KiB) Viewed 33 times
5. Write a function with header [f] = MyMultOperation(a,b,operation). The input argument, operation, is a string that is
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
5. Write a function with header [f] = MyMultOperation(a,b,operation). The input argument, operation, is a string that is
5. Write a function with header [f] = MyMultOperation(a,b,operation). The input argument, operation, is a string that is either 'plus', 'minus', 'mult', 'div', or 'pow', and fshould be computed as a + b, a- b, ab, a/b, and a ^b for the respective values for operation. Be sure to make your function vectorized. Hint: Use the strcmp function. Test Cases: >> x = [1 2 3 4]; [2 3 4 5]; >>y >> f = myMultOperation (x, y, 'plus') f- 5 7 9 >> f = myMultOperation (x, y, 'minus') f- -1 -1 -1 -1 >> f = myMultOperation (x, y, "mult') 2 6 12 20 >> f = myMultOperation (x, y, 'div') f - 0.5000 0.6667 >> f = myMultOperation f= 1 3 0.7500 0.8000 (x, y, 'pow') 8 81 1024