exp( x)sin(2 ) I x dx = − y ax bx cx d = + ,i x y , , 2, 20 , 0,4

advertisement
Introduction to Scientific and Engineering Computing
BIL 108E
Autumn 2013-2014
LAB 11
2Π
1) Write an m‐file function that evaluates
∫ sin (x) dx
2
using the composite trapezoid rule, and
0
composite Simpson’s rule, with four nodes per panel. Place the calls to Trapezoid, and Simpson inside
a loop and repeat the calculations for np = [2 4 8 16 32 64], where np is the number of panels. Record
the number of function evaluations, n, for each method.
2) (a) Write a script file to integrate a function contained in an m‐file using the Simpson rules. Use
your numerical integration scheme to evaluate
∞
=
I
∫ exp(− x)sin(2 x ) dx
0
Note that you cannot integrate to ∞, but the integrand decays rapidly, so practically you may
truncate the integral at some finite distance from the origin. Plot the integrand and choose the
practical upper limit for numerical integration.
(b) Compute the integral for several values of n (the number of integration points), ranging for 1 – 10
using Simpson’s rule. Make a table comparing the values.
(c) Use MATLAB functions trapz or quad to integrate the function and compare with your answers.
3) Suppose that it is known that the graph of the function y = ax 3 + bx 2 + cx + d passes through
four given points ( xi , yi ) , i = 1, 2,3, 4 . Write a user-defined function that accepts these four points
as input and computes the coefficients a, b, c and d. The function should solve four linear equations
in terms of the four unknowns a, b, c and d. Test your function for the case where
( xi , yi ) =−
( 2, −20 ) , ( 0, 4 ) , ( 2,68) , ( 4,508) .
4) The following function is linear in the parameters a1 and a2.
y(x)= a1 + a2 lnx
Use the least-square regression with the following data to estimate the values of a1 and a2. Use the
curve fit to estimate the values of y at x=2.5 and x=11.
x
y
1
10
2
14
3
16
4
18
5
19
6
20
7
21
8
22
9
23
10
23
Introduction to Scientific and Engineering Computing
BIL 108E
5) Determine the lowest positive root
of f (x) 7sin(x) e − x − 1
=
(a) Graphically
(b) Using the Newton-Raphson method
Autumn 2013-2014
Download