Homework Problem Set 4, Due Monday September 19, 2016. -------------------------------------------------------- Assigned 9/12/2016, due 9/19 (a) Write a function that will, for any input scalar-valued numeric function "ffcn" (of a numeric vector input) taken as argument, check whether "ffcn" is (everywhere) convex. Assume that along with "ffcn"there is an argument "Dom", a possibly infinite hyper-rectangle in a Euclidean space given as a Kx2 matrix, to which the argument-vector x of ffcn(x) is restricted, defined as the Cartesian product of intervals [Dom[i,1],Dom[i,2]]. Here Dom[,1] may have entries -Inf and Dom[,2] may have entries Inf. The definition of a function g(x) being "convex" is that for any vectors x and y (of the same dimension K, in the domain of g) and any number t in (0,1), g(t*x+(1-t)*y) <= t*g(x) + (1-t)*g(y). #---------------------------------------------------------------------- NOTE: in the earlier version of this posted assignment, the inequality sign in this definition was reversed !! THIS is the correct definition. #---------------------------------------------------------------------- HINT: check the validity of this inequality at a lot of randomly generated points x and y in the domain, with a variety of randomly generated t's. NOTE: for functions g that can be assumed to be smooth (twice continuously differentiable), convexity holds if and only if the "Hessian" matrix of second derivatives is nonnegative-definite. Explain how your code can be speeded up if you have an analytical Hessian of "ffcn" (the KxK matrix-valued function on domain "Dom" of the second partial derivatives of ffcn) given as an "atribute". Apply your function to check the convexity, for fixed vectors probvec and cvec of the same length n, where probvec is a probability vector, of the function WITH SCALAR ARGUMENT defined as h = function(x, probvec, cvec) c(outer(x,cvec, function(x,y) abs(x-y)) %*% probvec) That is apply your function to h as first argument with secnd argument Dom defined as some (bounded) interval, like Dom=array(c(-2,2),c(1,2)). [Recall that Dom must be a matrix.] Parenthetical Remark (not needed for the problem): Here x is scalar but the function actually vectorizes, i.e., for any k-vector xvec (k not the same as n = length(probvec)), h(xvec,probvec,cvec) has value equal to the vector of length k with i'th entry h(xvec[i],probvec,cvec). (b) Write a function named "Compose" which accepts function arguments f1, f2 (each of which has scalar argument x and numeric scalar value, and depends on a parameter, respectively a for f1 and b for f2 so that f1(x,a) and f2(x,b) are scalars) and outputs the function g(y,a,b) equal at fixed y,a,b values to f1(f2(y,b), a). Show on simple examples that your coded function works.