Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to calculate the square root of 16.
MATLAB
result = sqrt([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong number inside sqrt, like 25 or 8.
✗ Incorrect
The sqrt function calculates the square root of the input number. Here, the square root of 16 is 4.
2fill in blank
mediumComplete the code to create a vector from 1 to 5.
MATLAB
vec = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1:10 creates a longer vector than needed.
✗ Incorrect
The colon operator 1:5 creates a vector with values from 1 to 5.
3fill in blank
hardFix the error in the code to compute the sum of elements in vector v.
MATLAB
total = [1](v); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
add or plus which are not functions for summing vectors.✗ Incorrect
The sum function adds all elements of the vector v.
4fill in blank
hardFill both blanks to create a vector of squares of numbers 1 to 5.
MATLAB
squares = ([1]:[2]).^2;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong start or end values like 2 or 10.
✗ Incorrect
The colon operator 1:5 creates numbers from 1 to 5. Squaring each gives the squares vector.
5fill in blank
hardFill all three blanks to create a vector of even numbers from 2 to 10.
MATLAB
evens = [1]:[2]:[3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using step 1 instead of 2, or wrong start/end values.
✗ Incorrect
The syntax start:step:end creates a vector starting at 2, stepping by 2, up to 10, giving even numbers.