Challenge - 5 Problems
Curve Fitting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of polyfit polynomial coefficients
What is the output of the following MATLAB code?
x = [1 2 3 4 5]; y = [2.2 4.8 7.1 8.9 11.3]; p = polyfit(x, y, 1); disp(round(p,1))
MATLAB
x = [1 2 3 4 5]; y = [2.2 4.8 7.1 8.9 11.3]; p = polyfit(x, y, 1); disp(round(p,1))
Attempts:
2 left
💡 Hint
Recall polyfit returns coefficients starting with highest degree term.
✗ Incorrect
polyfit fits y = p1*x + p2. The slope is about 2.2 and intercept about 0.2 after rounding.
❓ Predict Output
intermediate2:00remaining
Result of fit with custom model
What is the value of the coefficient 'a' after running this MATLAB code?
x = (1:5)'; y = [2.2 4.8 7.1 8.9 11.3]'; ft = fittype('a*x+b'); f = fit(x,y,ft); disp(round(f.a,1))MATLAB
x = (1:5)'; y = [2.2 4.8 7.1 8.9 11.3]'; ft = fittype('a*x+b'); f = fit(x,y,ft); disp(round(f.a,1))
Attempts:
2 left
💡 Hint
Coefficient 'a' is the slope in the linear model.
✗ Incorrect
The fit finds a slope close to 2.2 matching the data trend.
❓ Predict Output
advanced2:00remaining
Output of polynomial evaluation after polyfit
What is the output of this MATLAB code?
x = 1:4; y = [1 8 27 64]; p = polyfit(x,y,3); val = polyval(p, 2.5); disp(round(val,1))
MATLAB
x = 1:4; y = [1 8 27 64]; p = polyfit(x,y,3); val = polyval(p, 2.5); disp(round(val,1))
Attempts:
2 left
💡 Hint
The data is cubic: y = x^3, so polyval should approximate 2.5^3.
✗ Incorrect
2.5^3 = 15.625, rounded to 15.6 matches option A.
❓ Predict Output
advanced2:00remaining
Error type from incorrect fit model syntax
What error does this MATLAB code produce?
x = (1:3)'; y = [2 4 6]'; ft = fittype('a*x^2 + b'); f = fit(x,y,ft);MATLAB
x = (1:3)'; y = [2 4 6]'; ft = fittype('a*x^2 + b'); f = fit(x,y,ft);
Attempts:
2 left
💡 Hint
Check if the model string syntax is valid for fittype.
✗ Incorrect
No error is produced; the expression 'a*x^2 + b' is valid because '^' is supported in fittype model strings.
🧠 Conceptual
expert2:00remaining
Choosing polynomial degree with polyfit
Given noisy data points, which polynomial degree chosen with polyfit is most likely to cause overfitting?
Attempts:
2 left
💡 Hint
Higher degree polynomials can fit noise, not just trend.
✗ Incorrect
A very high degree polynomial (like 10) fits noise and causes overfitting, losing generalization.