In: Mechanical Engineering
Create four anonymous functions to represent the function 6e3cosx2, which is composed of the functions h(z) = 6ez, g(y) = 3 cos y, and f(x) = x2. Use the anonymous functions to plot 6e3cosx2 over the range 0 ≤ x ≤ 4.
It is required to create four anonymous functions to represent
6e3cos(x2)
And plot it over the range
0 ≤ x ≤ 4
The other three functions are
h(z) = 6ez
g(y) = 3cos(y)
f(x) = x2
We can use the MATLAB syntax for creating the function
func = @ (x) ‘Expression’ and we can use the plot command to plot.
The MATLAB code is given below. Three simple functions given are to be compounded to achieve the fourth function. We need to calculate the function of function.
Input:
% creating functions
f = @(x) x.^2;
g = @(y) 3*cos(y);
h = @(z) 6.*exp(z);
% generating data points
x = 0:0.01:4;
% creating the fourth function
y = h(g(f(x)));
plot(x, y)
grid on
Output:
It is required to create four anonymous functions to represent
6e3cos(x2