0
0
MATLABdata~20 mins

Function handles in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Function Handle Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple function handle call
What is the output of this MATLAB code?
MATLAB
f = @(x) x^2 + 3*x + 1;
result = f(2);
disp(result);
A15
B9
C7
D11
Attempts:
2 left
💡 Hint
Calculate 2 squared plus 3 times 2 plus 1.
Predict Output
intermediate
2:00remaining
Function handle with multiple inputs
What is the output of this MATLAB code?
MATLAB
g = @(x,y) x*y + y^2;
val = g(3,4);
disp(val);
A28
B19
C25
D16
Attempts:
2 left
💡 Hint
Calculate 3*4 + 4^2.
🔧 Debug
advanced
2:00remaining
Identify the error in function handle usage
What error does this MATLAB code produce?
MATLAB
h = @(x) x(2) + 5;
result = h(3);
disp(result);
AUndefined function or variable 'x'.
BIndex exceeds matrix dimensions.
CSyntax error: missing operator.
DNo error, output is 8.
Attempts:
2 left
💡 Hint
Check how x is used inside the function handle.
🧠 Conceptual
advanced
2:00remaining
Function handle behavior with variable scope
Consider this MATLAB code snippet. What is the output?
MATLAB
a = 10;
f = @(x) x + a;
a = 20;
disp(f(5));
A15
BError: Undefined variable 'a'.
C25
D5
Attempts:
2 left
💡 Hint
Anonymous functions in MATLAB capture variables by value at the time of creation.
Predict Output
expert
2:00remaining
Output of nested function handles with array input
What is the output of this MATLAB code?
MATLAB
f1 = @(x) x.^2;
f2 = @(g, y) g(y) + 1;
arr = [1, 2, 3];
result = f2(f1, arr);
disp(result);
A[1 4 9]
B[2 4 6]
C[2 5 10]
DError: Matrix dimensions must agree.
Attempts:
2 left
💡 Hint
Apply f1 to each element of arr, then add 1 to each result.