Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '#' or '$' instead of '@' to create function handles.
Forgetting the '@' symbol before the function input.
✗ Incorrect
In MATLAB, function handles are created using the '@' symbol followed by the function input arguments.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets or curly braces instead of parentheses.
Omitting parentheses when calling the function handle.
✗ Incorrect
Function handles are called using parentheses with the input value inside.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'function' keyword instead of '@'.
Using undefined keywords like 'handle' or 'fun'.
✗ Incorrect
Anonymous function handles in MATLAB start with '@', not 'function' or other keywords.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' or '*' instead of '+' for addition.
Forgetting the '@' symbol before the input arguments.
✗ Incorrect
The '@' symbol defines the function handle, and '+' adds the two inputs.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' for subtraction.
Using '*' instead of '^' for power.
Omitting '@' at the start.
✗ Incorrect
Use '@' to define the function handle, '^' for power, and '-' to subtract the two results.