Bird
0
0

Given a function f(x) = exp(-x^2), how can you numerically integrate it from -2 to 2 in MATLAB with high accuracy?

hard📝 Application Q9 of 15
MATLAB - Numerical Methods
Given a function f(x) = exp(-x^2), how can you numerically integrate it from -2 to 2 in MATLAB with high accuracy?
AUse <code>quad</code> function with function handle
BUse <code>trapz</code> on <code>x = -2:0.1:2</code> and <code>y = exp(-x.^2)</code>
CUse <code>integral(@(x) exp(-x.^2), -2, 2)</code>
DUse symbolic integration with <code>int</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand function and integration range

    Function is smooth, integration limits are finite.
  2. Step 2: Choose numerical method

    integral uses adaptive quadrature, providing high accuracy for smooth functions.
  3. Step 3: Compare other options

    trapz is less accurate due to fixed step size, quad is older, symbolic int may not have closed form.
  4. Final Answer:

    Use integral(@(x) exp(-x.^2), -2, 2) -> Option C
  5. Quick Check:

    integral with function handle for high accuracy [OK]
Quick Trick: integral adapts intervals for accuracy, best for smooth functions [OK]
Common Mistakes:
  • Using trapz with coarse step size
  • Using deprecated quad function
  • Expecting symbolic integral always works

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes