Question: Creating Anonymous Functions Background Function handles ( i . e . , anonymous functions ) are useful because they allow you to treat calculations in

Creating Anonymous Functions
Background
Function handles (i.e., anonymous functions) are useful because they allow you to treat calculations in MATLAB much like you would hand calculations. That is, funciton handles allow you to calculate the value of some expression (function) much like you would in your math and physics classes. There are, of course, some MATLAB-specific syntax issues you need to be aware of; you will practice some of these syntactical specifics here.
Your Task
Write a script that accomplishes the following:
- Define an anonymous function, \(\mathbf{f}\), that represents \( f(x)=\frac{\sin (x)+4 x}{x^{2}}\)
- Evaluate \( f(5)\) using f and store the output to a variable called \(\mathbf{A}\).
- Define a second anonymous function, \(\mathbf{g}\), that represents \( g(x)=e^{\left(\cos (x)^{k}\right)}\), where \( e \) is Euler's number and k is a random variable defined by a locked line in the script template.
- Evaluate \( g(\pi /4)\) using \(\mathbf{g}\) and store the output to a variable called \(\mathbf{B}\).
- Define a row vector, \(\mathbf{x}\), starting at 0 and ending at 1 with each element spaced by 0.1.
- Evaluate \( g(f(g(x)))\) and store the output to a variable called \(\mathbf{C}\).
Note: Make sure your function handles work for array inputs!
Script \({}^{\circ}\)
MATLAB Documentation
```
k = randn(1); % random variable; do not redefine k!
% define all of your variables below
```
Creating Anonymous Functions Background Function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!