Not sure why I am getting errors for my anonymous functions.
6 views (last 30 days)
Show older comments
I have this code:
k = randn(1); % random variable
% define all of your variables below
f = @(x) (sin(x)+4.*x)/x.^2
A = f(5)
g = @(x,k) exp(cos(x)).^k
B = g(pi/4,k)
x = [0:0.1:1]
C = g(f(g(x)))
and when I run it I get these two errors:
Not enough input arguments.
Error in solution>@(x,k)exp(cos(x)).^k (line 5)
g = @(x,k) exp(cos(x)).^k
Error in solution (line 8)
C = g(f(g(x)))
0 Comments
Answers (2)
Voss
on 12 Feb 2023
That's one error.
g takes two inputs, but you are giving it only one when you use it here:
C = g(f(g(x)))
The input given to g is x. What k is it supposed to use?
0 Comments
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!