0
0
MATLABdata~10 mins

Function handles in MATLAB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a function handle that squares a number.

MATLAB
square = [1](x) x^2;
Drag options to blanks, or click blank then click option'
A%
B#
C$
D@
Attempts:
3 left
💡 Hint
Common Mistakes
Using '#' or '$' instead of '@' to create function handles.
Forgetting the '@' symbol before the function input.
2fill in blank
medium

Complete the code to call the function handle 'f' with input 5.

MATLAB
result = f[1]5;
Drag options to blanks, or click blank then click option'
A( )
B{ }
C[ ]
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Omitting parentheses when calling the function handle.
3fill in blank
hard

Fix the error in the function handle definition to correctly compute the cube of x.

MATLAB
cube = [1](x) x^3;
Drag options to blanks, or click blank then click option'
Afunction
B@
Chandle
Dfun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'function' keyword instead of '@'.
Using undefined keywords like 'handle' or 'fun'.
4fill in blank
hard

Fill both blanks to create a function handle 'add' that adds two inputs a and b.

MATLAB
add = [1](a, b) a [2] b;
Drag options to blanks, or click blank then click option'
A@
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' or '*' instead of '+' for addition.
Forgetting the '@' symbol before the input arguments.
5fill in blank
hard

Fill all three blanks to create a function handle 'powerDiff' that computes a^n minus b^n.

MATLAB
powerDiff = [1](a, b, n) a[2]n [3] b[2]n;
Drag options to blanks, or click blank then click option'
A@
B^
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' for subtraction.
Using '*' instead of '^' for power.
Omitting '@' at the start.