Reference no: EM132199052
a) Write a function magnitude that computes the magnitude of a vector, i.e., the square- root of the sum of the squares of the components of the vector.
b) Write a function inner_prod that computes the inner product (i.e., dot product) of two vectors.
c) Write a function num_to_month that computes the string name of the month from an input integer from 1 to 12. The behavior on another input is unspecified.
d) Write a predicate (a function that returns true or false) is_divisible that takes two integers and determines whether the first is divisible by the second, return true in that instance and false otherwise.
e) Write a predicate is_leap_year that determines whether a year, given as a positive
number is a leap year or not. Use is_divisible and the following rules in order:
i) If the year is not evenly divisible by 4, then it is NOT a leap year.
ii) If the year is evenly divisible by 4, but not 100, then it is a leap year.
iii) If the year is evenly divisible by 400, then it is NOT a leap year, otherwise it is a
leap year.
f) Write a function cross_prod that computes the cross product of two length-three vectors. (Do not use a built-in MATLAB functions to accomplish this.)
g) Write a function called pair that takes two numbers x and y and returns a vector of length two with x in the first cell and y in the second cell.
h) Write a function components that computes the horizontal and vertical components of a vector specified by a positive length and an angle in degrees (counter-clockwise from the positive x-axis). Your function should return two values: the x-component of the vector, then the y-component.
i) Write a function components_vec that performs the same computation as in the previous question, but instead returns a vector of length two with the same results. Use the function pair you wrote above.
j) Write a function average_point that takes three vectors xs, ys, zs of length n and computes the average of the n points described by these vectors. If not all vectors are the same length return the point (0, 0, 0). This function returns a vector of length 3.
k) Trace the following code:
clear; clc; x = 0;
y = 15
z = 30;
x = run_test(z);
function y = run_test(x) y = x;
x = pi; end