0
0
MATLABdata~20 mins

Numerical differentiation in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Numerical Differentiation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of forward difference approximation
What is the output of this MATLAB code that approximates the derivative of f(x) = x^2 at x = 2 using the forward difference method with h = 0.01?
MATLAB
f = @(x) x.^2;
x = 2;
h = 0.01;
derivative = (f(x + h) - f(x)) / h;
disp(derivative);
A4.01
B4.00
C3.99
DError: Undefined function or variable 'f'
Attempts:
2 left
💡 Hint
Recall the formula for forward difference: (f(x+h) - f(x)) / h.
Predict Output
intermediate
2:00remaining
Output of central difference approximation
What is the output of this MATLAB code that approximates the derivative of f(x) = sin(x) at x = pi/4 using the central difference method with h = 0.001?
MATLAB
f = @(x) sin(x);
x = pi/4;
h = 0.001;
derivative = (f(x + h) - f(x - h)) / (2*h);
disp(derivative);
A0.7060
B0.7070
C0.7071
DError: Index exceeds matrix dimensions.
Attempts:
2 left
💡 Hint
Central difference formula is (f(x+h) - f(x-h)) / (2*h).
🔧 Debug
advanced
2:00remaining
Identify the error in backward difference code
This MATLAB code attempts to compute the derivative of f(x) = exp(x) at x = 1 using the backward difference method with h = 0.01. What error will it produce when run?
MATLAB
f = @(x) exp(x);
x = 1;
h = 0.01;
derivative = (f(x) - f(x - h)) / h;
AIndex exceeds matrix dimensions.
BNo error; outputs approximately 2.7183
CSyntaxError: Missing semicolon
DUndefined function or variable 'h'
Attempts:
2 left
💡 Hint
Check if the code syntax is correct and variables are defined.
Predict Output
advanced
2:00remaining
Output of second derivative approximation
What is the output of this MATLAB code that approximates the second derivative of f(x) = x^3 at x = 2 using the central difference formula with h = 0.001?
MATLAB
f = @(x) x.^3;
x = 2;
h = 0.001;
second_derivative = (f(x + h) - 2*f(x) + f(x - h)) / (h^2);
disp(second_derivative);
A12.0000
BError: Undefined function or variable 'second_derivative'
C13.0000
D11.9990
Attempts:
2 left
💡 Hint
Recall the second derivative central difference formula: (f(x+h) - 2f(x) + f(x-h)) / h^2.
🧠 Conceptual
expert
2:00remaining
Error behavior in numerical differentiation
Which statement correctly describes the error behavior when using the central difference method to approximate the first derivative of a smooth function as the step size h approaches zero?
AThe error increases exponentially as h decreases.
BThe error is constant regardless of h.
CThe error always decreases as h approaches zero without limit.
DThe error decreases linearly with h and then increases due to round-off errors for very small h.
Attempts:
2 left
💡 Hint
Consider both truncation and round-off errors in numerical differentiation.