MATH/CMSC 206 - Introduction to Matlab
Announcements | Syllabus | Tutorial | Projects | Submitting |
Answers to Self-Test
1. Try using int to symbolically calculate the definite integral of the function f(x) = sqrt(x + ln(x)) over the interval [10, 20]. It may take a while. After all that waiting, when you finally see the answer you will be very disappointed! That was useless. Now try it using quad.
syms x
int(sqrt(x + log(x)), 10, 20)
Warning: Explicit integral could not be found. ans = int((x + log(x))^(1/2), x = 10..20)
quad(@(x) sqrt(x + log(x)), 10, 20)
ans = 41.8953
2. Try to find the definite integral of the function f(x) = 2^sin(x) over the interval [1, 2] using both symbolic and numerical methods. Hint: To get this function to work properly with quad, you'll have to use the symbol .^ instead of ^ for exponentiation. Later, you'll learn why!
int (2^sin(x), 1, 2)
Warning: Explicit integral could not be found. ans = int(2^sin(x), x = 1..2)
quad(@(x) 2.^sin(x), 1, 2)
ans = 1.9413