Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add two numbers and store the result in sum.
MATLAB
a = 5; b = 3; sum = a [1] b;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication
* instead of addition.Using division
/ instead of addition.✗ Incorrect
The plus sign + adds two numbers in MATLAB.
2fill in blank
mediumComplete the code to multiply two numbers and store the result in product.
MATLAB
x = 7; y = 4; product = x [1] y;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition
+ instead of multiplication.Using division
/ instead of multiplication.✗ Incorrect
The asterisk * multiplies two numbers in MATLAB.
3fill in blank
hardFix the error in the code to correctly divide num1 by num2.
MATLAB
num1 = 10; num2 = 2; result = num1 [1] num2;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication
* instead of division.Using subtraction
- instead of division.✗ Incorrect
The forward slash / divides one number by another in MATLAB.
4fill in blank
hardFill both blanks to calculate the remainder when a is divided by b.
MATLAB
a = 17; b = 5; remainder = mod([1], [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the numbers directly instead of variables.
Swapping the order of inputs.
✗ Incorrect
The mod function returns the remainder of division. Use the variables a and b as inputs.
5fill in blank
hardFill both blanks to create a vector of squares of numbers from 1 to 5.
MATLAB
numbers = 1:5; squares = numbers [1] [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
^ instead of .^ which causes an error for vectors.Using multiplication
* instead of power operator.✗ Incorrect
In MATLAB, .^ is the element-wise power operator. To square each element, use .^ 2. The multiplication operator * is not used here.