Answer:
a)
A compose function is defined between the two functions or more functions.
Here for simplicity, the compose function accepts two functions and are considered as single argument.
In a compose function, depending on the defining the functional flow, the value is evaluated.
To compose (f, g) on x, then it will be computed as, f(g(x)).
Method in Scheme:
Define the function called compose, on two functions called f and g with a value x.
Internally define a lambda function on x where
It first evaluates the g(x).
The obtained resultant from g(x) will pass as value into function f.
Then final result obtained from the f(g(x)) will be returned to the call function.
The value calculation is based on the functions that are passed in place of f and g.
Example:
Compute the value of acos(sin(0)).
Here sin() is function g,acos() is function f and x = 0.
Scheme:
; define the function compose on two functions
; f and g and return the value computed by f(g(x))
(define (compose f g)
(lambda (x) (f (g x))))
; function call to find the value of acos(sin(0))
; first test case
(display ((compose acos sin) 0))
(newline)
; function call to find the value of cos(sin(0))
; first test case
(display ((compose cos sin) 0))
(newline)
Sample Output:
Code screen shot:
b)
Scheme function screen shot:
(a) Explain the method of making composed functions in Scheme. Show an example of a composed...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (first-n L1 N) that returns the first N elements of L1. If N is negative, return the empty list. If N exceeds the length of L1 return all elements of L1. (first-n...
Consider this scheme function and explain it
Consider the following Scheme function: (define f (lambda (1st) (cond (null? 1st)) 0) ((number? (car 1st) (+ 1 (f (cdr 1st)))) (else (f (cdr 1st))))) Explain what the function f computes for lists. consider (f '(1 a b 2)) for example.
6.5 A simple example of an optimization method is the random search method. This method repeatedly evaluates the function at randomly selected values of the optimization variables. If a sufficient number of samples are conducted, the optimum would eventually be found. Consider the optimization problem min f(x,y) = -8x + x2 +12y + 4y2 – 2xy x,y a. Write down the step-to-step algorithm you would use to solve the problem. b. Implement your algorithm in MATLAB to solve the problem....
Question 2 (20 points): Consider the functions f(x, y)-xe y sin y and g(x, y)-ys 1. Show f is differentiable in its domain 2. Compute the partial derivatives of g at (0,0) 3. Show that g is not differentiable at (0,0) 4. You are told that there is a function F : R2 → R with partial derivatives F(x,y) = x2 +4y and Fy(x, y 3x - y. Should you believe it? Explain why. (Hint: use Clairaut's theorem)
Question 2...
Objective To program using the functional programming paradigm Assignment: Write the following functions using Scheme (or LISP if you prefer) . A function (binomial N k) that returns the binomial coefficients C(N, k), defined recursively as: C(NO) = 1, C(N, N) = 1, and, for 0<k < N E(N, k) = C(N-1, k) + C(N-1, k-1) 2. A function (mod N M) that returns the modulus remainder when dividing N by M 3. A function (binaryToDecimal b) that takes a...
The equation f(x) = (1 ‐ x) cos x ‐ sin x = 0 has at least one root between a = 0 and b = 1 since f(a)f(b) < 0. The bisection method of finding the root proceeds as follows: a. It finds the midpoint r = (a + b)/2. b. If f(r) = 0, then r is the root. If |b ‐ a| is very small less than ∈ then also we can take r as the root....
Background to this question Functions can return booleans, which is often convenient for hiding complicated tests inside functions. For example: def is_divisible(x, y): if x % y == 0: return True else: return False It is common to give boolean functions names that sound like yes/no questions; is_divisible returns either True or False to indicate whether x is divisible by y. Here is an example: >>> is_divisible(6, 4) False >>> is_divisible(6, 3) True The result of the == operator is...
6. (a) Newton's method for approximating a root of an equation f(x) 0 (see Section 3.8) can be adapted to approximating a solution of a system of equations f(x, y) 0 and gx, y) 0. The surfaces z f(x, y) and z g(x, y) intersect in a curve that intersects the xy-plane at the point (r, s), which is the solution of the system. If an initial approxi- mation (xi, yı) is close to this point, then the tangent planes...
Definition 5.48. Let f,g:X + Y be functions and assume that Y is a set in which the following operations make sense. Then the following are also functions: 1. f + g defined by (f +g)(x) = f(x) + g(x) for all x E X 2. f - g defined by (f – g)(x) = f(x) – g(x) for all x € X 3. f.g defined by (fºg)(x) = f(x) · g(x) for all x E X f(x) = "147...
For each of the following functions, determine the value of c for which the function is a joint pdf of two continuous random variables X and Y. (a) f(x,y) = cry, 0 <r<1,7 <y<r. (b) f(r,y) = c(1+r+y), 0 <r<y<1. (c) f( y) = cye.0<r<y.0<y<1. (d) f(x,y) = csin(x+y), 0<I< /2.0 <y < /2. (e) f(x,y) = cr(1-y), 0 <y<1,0 <r<1-y.