Bird
0
0

Consider the MATLAB code:

medium📝 Predict Output Q13 of 15
MATLAB - Numerical Methods
Consider the MATLAB code:
f = @(x) x^2;
x = 2;
h = 0.01;
df = (f(x+h) - f(x-h)) / (2*h);

What is the value of df approximately?
A5.00
B2.00
C4.00
D3.99
Step-by-Step Solution
Solution:
  1. Step 1: Calculate f(x+h) and f(x-h)

    f(2+0.01) = (2.01)^2 = 4.0401; f(2-0.01) = (1.99)^2 = 3.9601.
  2. Step 2: Compute central difference

    df = (4.0401 - 3.9601) / (2*0.01) = 0.08 / 0.02 = 4.00.
  3. Step 3: MATLAB precision

    In MATLAB, df is computed and displayed as 4.0000.
  4. Final Answer:

    4.00 -> Option C
  5. Quick Check:

    Central difference ≈ 4 [OK]
Quick Trick: Central difference approximates slope near x [OK]
Common Mistakes:
  • Using forward difference formula instead
  • Forgetting to divide by 2*h
  • Incorrect function evaluation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes