Covariance measures how two variables change together. If they increase or decrease together, covariance is positive; if one increases while the other decreases, covariance is negative.
Click to reveal answer
beginner
What does correlation measure?
Correlation measures the strength and direction of a linear relationship between two variables. It is normalized between -1 and 1.
Click to reveal answer
beginner
How do you calculate covariance in MATLAB?
Use the function cov(X) where X is a matrix or vectors of data. It returns the covariance matrix.
Click to reveal answer
beginner
How do you calculate correlation in MATLAB?
Use the function corrcoef(X) where X is a matrix or vectors. It returns the correlation coefficient matrix.
Click to reveal answer
intermediate
What is the difference between covariance and correlation?
Covariance shows how two variables vary together but depends on their units. Correlation standardizes this, showing strength and direction on a scale from -1 to 1.
Click to reveal answer
What does a correlation coefficient of 0 indicate?
ANo linear relationship between variables
BPerfect positive linear relationship
CPerfect negative linear relationship
DVariables are identical
✗ Incorrect
A correlation of 0 means no linear relationship between the variables.
Which MATLAB function returns the covariance matrix?
Acorrcoef
Bmean
Cstd
Dcov
✗ Incorrect
The cov function returns the covariance matrix.
If covariance between two variables is negative, what does it mean?
ABoth variables increase together
BVariables are independent
COne variable increases while the other decreases
DVariables have no relationship
✗ Incorrect
Negative covariance means when one variable increases, the other tends to decrease.
What is the range of correlation coefficient values?
A0 to 1
B-1 to 1
C-∞ to ∞
D0 to 100
✗ Incorrect
Correlation coefficients range from -1 (perfect negative) to 1 (perfect positive).
Which MATLAB function would you use to find the correlation between two data vectors X and Y?
Acorrcoef(X, Y)
Bcov(X, Y)
Cmean(X, Y)
Dstd(X, Y)
✗ Incorrect
Use corrcoef(X, Y) to compute the correlation coefficient matrix.
Explain the difference between covariance and correlation and how you calculate each in MATLAB.
Think about how covariance depends on units but correlation does not.
You got /4 concepts.
Describe what a positive, negative, and zero covariance indicate about two variables.
Consider how variables move together or apart.
You got /3 concepts.
Practice
(1/5)
1.
What does the MATLAB function cov compute?
easy
A. Standard deviation of a variable
B. Covariance matrix showing how two variables vary together
C. Mean value of a dataset
D. Correlation coefficient between two variables
Solution
Step 1: Understand the purpose of cov
The cov function calculates the covariance matrix, which shows how two variables change together.
Step 2: Differentiate covariance from correlation
Correlation measures strength and direction, but cov specifically returns covariance values.
Final Answer:
Covariance matrix showing how two variables vary together -> Option B
Thinking cov returns a single value instead of a matrix
Mixing up cov with mean or std functions
2.
Which of the following is the correct syntax to calculate the correlation matrix of variables X and Y in MATLAB?
?
easy
A. R = cov(X, Y);
B. R = correlation(X, Y);
C. R = corrcoef(X, Y);
D. R = corr(X, Y);
Solution
Step 1: Identify MATLAB function for correlation
The correct MATLAB function to compute correlation coefficients is corrcoef.
Step 2: Check syntax correctness
The syntax R = corrcoef(X, Y); correctly computes the correlation matrix between X and Y.
Final Answer:
R = corrcoef(X, Y); -> Option C
Quick Check:
corrcoef syntax = R = corrcoef(X, Y) [OK]
Hint: Use corrcoef for correlation, not cov [OK]
Common Mistakes:
Using cov instead of corrcoef for correlation
Using non-existent functions like correlation or corr
Missing parentheses or semicolon
3.
What is the output of the following MATLAB code?
X = [1 2 3];
Y = [4 5 6];
R = corrcoef(X, Y);
disp(R);
medium
A. [[1 0]; [0 1]]
B. [[1 0.5]; [0.5 1]]
C. [[1 -1]; [-1 1]]
D. [[1 1]; [1 1]]
Solution
Step 1: Understand the data vectors
Vectors X and Y are perfectly linearly related: Y = X + 3.
Step 2: Calculate correlation coefficient
Since they have a perfect positive linear relationship, correlation coefficient is 1.
Final Answer:
[[1 1]; [1 1]] -> Option D
Quick Check:
Perfect positive correlation = 1 [OK]
Hint: Perfect linear relation means correlation = 1 [OK]
Common Mistakes:
Assuming correlation less than 1 for linear relation
Confusing covariance with correlation values
Misreading matrix output format
4.
Identify the error in this MATLAB code snippet:
X = [1 2 3];
Y = [4 5 6];
R = corrcoef(X Y);
disp(R);
medium
A. Missing comma between X and Y in corrcoef function
B. Vectors X and Y must be column vectors
C. corrcoef cannot take two inputs
D. disp cannot display matrices
Solution
Step 1: Check function call syntax
The function call corrcoef(X Y) is missing a comma between X and Y.
Step 2: Confirm correct syntax
The correct syntax is corrcoef(X, Y) with a comma separating inputs.
Final Answer:
Missing comma between X and Y in corrcoef function -> Option A
Quick Check:
Function arguments need commas [OK]
Hint: Separate function arguments with commas [OK]
Common Mistakes:
Omitting commas between function arguments
Thinking vectors must be columns for corrcoef
Believing disp cannot show matrices
5.
You have two datasets A = [1 2 3 4] and B = [2 4 6 8]. You want to check if B is exactly twice A using correlation and covariance. Which MATLAB code snippet correctly confirms this?