Sie sind auf Seite 1von 12

1.

Winter 2008

For the equation: x  ex  1

a. Perform 2 iterations Using the Bisection method for finding a root in the range
[0,1] (6 pts)

f (0)  1  0  f min  x min  0


f (1)  1.7183  0  f max  x max  1

x min  x max
xnew   0.5
2
f (0.5)  0.1756  0  f min  x min  0.5

x min  x max
xnew   0.75
2
f (0.75)  0.5878  0  f max  x max  0.75
b. What is the maximal error in the value of x obtained in ‘a’ (4 pts)

1−0
E𝑚𝑎𝑥 = = 0.25
22

c. What will be the maximal error after 10 iterations (Note: there is no need to
perform more iterations at this stage)

1 0
E max   9.7656e-004
210
d. Find the root using Newton-Raphson method using initial guess x=0 and stop
f ( x )  0.1
criteria
f (0)  xe x  1  1
f (0)  e x  xe x  1

f (0)
x0 1
f (0)
f (1)  xe x  1  1.7183
f (1)  e x  xe x  2e  5.4366

f (1)
x 1  0.6839
f (1)
f (0.6839)  xe x  1  0.3552
f (0.6839)  e x  xe x  3.3368

f (0.6839)
x  0.6839   0.5775
f (0.6839)
f (0.5775)  xe x  1  0.0289 < 0.1

e. Find at least one point which cannot be used as an initial guess in the Newton-
Raphson method. Explain the calculation.

f ( x)  xe x  1
f ( x)  e x  xe x
x  1  f ( x)  0

2. Winter 2008 (20 pts)

In a two dimensional world, an arrow is shot in time t=0 from the coordinate x=1,
y=0.

 2x
The velocity of the arrow in x direction is given by: x' (t ) 
x2  y2

 2y
and in the y direction y ' (t )  1 
x2  y2
a. Define the problem in terms of order, given conditions and linearity. Point
out the dependent and independent variables. (5 pts)

Initial conditions, Linear, 1st order


t – dependent variables
x,y – independent variables

b. Develop the general expression of the numerical solution to the problem


with an explicit solution method. (8pts)

Euler :
 2 xi 
 x2  y2 
 xi 1   xi   *h
y   y   
i i

 i 1   i  1  2 xi 
 
 xi
2
 yi 
2

c. Calculate the location of the arrow up to the point where y  0.15 , use the
step size h=0.1. (8 pts)

x0  1 y0  0 h  0.1
 2 x0 
 x0 2  y0 2 
 x1   x0   0.8
y   y    2 x0 
*h   
 1  0  1  0.1
 
 x0 2  y0 2 
 2 x1 
 x1  y1 
 x2   x1   0.6015
2 2

y   y    2 x1 
*h    y2  0.15
 2   1 1 0.1752
 
 x12  y12 
3. Winter 2008 (22 pts)

The following function ranks matrices according to the Gauss method with partial
pivoting. This function does not include the backward substitution stage.

1 function [a,b] = pg(a,b)


2 [m,n] = size(a);
3 % input check
Complete 1
4 if m~=n | length(b)~=m
error(‘dimension must agree’);
end
5 % pivoting
6 for j = 1:n-1
Complete 2
7 pivot = abs(a(j,j));
8 k = j;
9 for i = j+1:m
Complete 3
10 if abs(a(i,j))>pivot
11 pivot = abs(a(i,j));
12 k = i;
13 end
14 end
15 if k ~= j
16 temp = a(j,:);
17 a(j,:) = a(k,:);
18 a(k,:) = temp;
Complete 4
19 temp = b(j); b(j) = b(k); b(k) = temp;
20 end
21 % ranking
22 m1 = a(j,j);
23 for i = j+1:n
24 m2 = a(i,j);
25 for q = j:n
26 a(i,q) = m1 * a(i,q) - m2 * a(j,q);
27 end
28 b(i) = m1 * b(i) - m2 * b(j);
29 end
30 end

a. What is the meaning and dimensions of ‘n’ and ‘b’ aN  N bN 1


b. Fill in Complete 1 this part perform two input checks and returns an error
message if the input is inappropriate.
c. Fill in the rest of the missing part (complete 2,3,4). Completion may include
more than one code line.

4. Spring 2007 (20 pts)


For the data given in the table:

xi 0 1 2 4
yi 1.2 2.1 2.2 0.0

a. Calculate the Lagrange interpolation curve fitting the data. (6pts)


b. Calculate the Newton interpolation curve fitting this data (6pts)
c. Write the full set of equations one has to solve to calculate square

splines for the given data. Plague all the known values and explain
what the unknowns are. No need to solve the equations.
Lagrange Polynom

Newton’s Polynom

C. The numbers of equations is 9:

6 equations for the points

P1 (0)  a01  a11  0  a21  0 2  1.2 



P1 (1)  a01  a11 1  a21 12  2.1 
P2 (1)  a02  a12 1  a22 12  2.1  
6
P2 (2)  a02  a12  2  a22  2  2.3
2

P3 (2)  a03  a13  2  a23  2 2  2.3 



P3 (4)  a03  a13  4  a23  4 2  0.5 

2 equations for the 1st derivative

P1 ' (1)  a11  2  a 21  1  


P2 ' (1)  a12  2  a 22  1 
2
P2 ' (2)  a12  2  a 22  2 
P3 ' (2)  a13  2  a 23  2 

1 arbitrary boundary condition

P1 ' (0)  a11  2  a 21  0  0

Unknowns:

a01 , a11 , a21 , a02 , a12 , a22 , a03 , a13 , a23 

5. Winter 2008 (25 pts)

The following function calculate the values of midpoints using the Lagrange
interpolation for known points:
1 function AAA=Lagrange(BBB,CCC,DDD)
2 n=size(CCC,2);
3 EEE=ones(n,size(BBB,2));
4 if (size(CCC,2)~=size(DDD,2) | n < 2)
5 fprintf('Error message);
6 AAA=NaN;
7 else
8 for i=1:n
9 for j=1:n
10 if Complete 1
11 EEE(i,:)=EEE(i,:) .* (BBB-CCC(j)) / (CCC(i)-CCC(j));
12 end
13 end
14 end
15 AAA=0;
16 for i=1:n
17 AAA=AAA + DDD(i) * complete 2;
18 end
19 end

a. What is the meaning of the variables AAA, BBB, CCC, DDD and EEE?
(10pts)
b. Write the general dimentions of the variables above. Use the same subscript if
the dimentions are identical for two or more variables
c. Fill in the missing code: Complete 1,2 (6 pts)
d. What are the errors, resulting in the error message in line 5 of the code.

a. AAA – Output, f(x) values obtained by the interpolation


BBB - x values corresponding to AAA
CCC - Given x values for which f(x) is known
DDD - f(x) values corresponding to CCC
EEE – Lagrange coefficients for the current interpolation

AAA(1M ) BBB(1M ) CCC(1N ) DDD(1N ) EEE( N M )


b.

c. Complete 1 - 1 i ~  j
Complete 2 - EEE (i,:)
d. (1) if the number of the given points is smaller than 2 (2) If the length of x vector
is different from that of f(x) vector

6. Winter 2008 (20 pts)


State true or false for the statements given below. Explain your answer shortly
(2-3 lines at most). The right answer without explanation or with a false
explanation will not gain points.
a. Some points cannot be used as initial guess for Newton-Raphson method
b. Multiplying the number of trapezes in the Trapezoid method decrease the
order of the error by a factor of 4
c. LU method is subject to rounding errors only
For the following sections on numerical integration: explain the ratio between
the errors' order of magnitude
d. Simpson in one segment compared to Simpson in N segments
e. Simpson in one segment compared to Trapezoid in one segment

‫א‬. True - point where f  x   0


b  a  b  a  b  a 
3 3 3

‫ב‬. True: E f    f    f 


12n 2 12(2  n)2 4  12n 2
‫ג‬. True
b  a 
5
ba
5

 b  a   N   
5

 N  N4
‫ד‬. ratio= N 4

O(h 4 )
O  h5 
‫ה‬. ratio=  O  h2 
Oh 3

Spring 2008 (40 pts)

1. for the following problem , a unique solution exists

d2y
y
dx 2
y '(1)  1
y '(3)  3

1.1 write the set of equations needed to be solved when using the finite differences
method with h  1 . Use the central approximation to calculate the 1st derivative
1.2 Solve the system using Thomas method. The matrix must be tridiagonal.
1.3 Can the problem be solved using the shooting method? Explain. No need for
calculation in this section.

2. Given the following problem:

d 2z
 z 1
dx 2
z '(1)  1
z '(3)  3
Based on section 1.2; what is the solution for this problem? Note the difference between
the problems

3. Given the following problem:

d2y
 f ( x)
dx 2
y '(1)  1
y '(3)  3

3.1 write the set of equations needed to be solved when using the finite differences
method with h  1 . Use the central approximation to calculate the 1st derivative.
note the similarity to section 1.3
3.2 Is there a unique solution for the system obtained? Explain. Note the values in the
coefficient matrix

111

y (0)  2 y (1)  y (2)  y (1)


y (1)  2 y (2)  y (3)  y (2)
y (2)  2 y (3)  y (4)  y (3)
y (2)  y (0)
1
2
y (4)  y (2)
3
2

112
For Thomas we need tridiagonal matrix so we have to substitute y(0) and y(4)
y (2)  y (0)
 1  y (0)  y (2)  2
2
y (4)  y (2)
 3  y (4)  6  y (2)
2
y (0)  2 y (1)  y (2)  y (1)   3 y (1)  2 y (2)  2
y (1)  2 y (2)  y (3)  y (2)  y (1)  3 y (2)  y (3)  0
y (2)  2 y (3)  y (4)  y (3)  2 y (2)  3 y (3)  6
 3 2 0  y (1)   2 
    
 1 3 1  y (2)    0 
 0 2 3  y (3)   6 
    
A y d




u1  3 
1    
l2   1
3 0 0   3 2 0 
   
1  1
u2  3  ( )  2  2   1 0    0 2 1  A
1 1
3 3  3   3 
2 6   6   1 
l3    0  1  0 0 2 
2
1 7  7   7

3  L U

 6 1
u3  3     1  2 
 7 7
Lx  d
x1  2
 1  2
x2  0     2 
 3  3
 6 2 3
x3  6       5
 7 3 7
Uy  x
3
5
7 8
y (3)  2
1 15
2
7
2 8
 1 2
3 15 4
y (2)  
1 5
2
3
4
2  2
y (1)  5  2
3 15

111

It is possible to solve using the shooting method:

a. Guess a value for y(1)


b. Using this guess and the boundary condition for x=1, solve the initial conditions
problem up to x=3
c. evaluate the derivative in x=3 using backward approximation and compare with the
given boundary condition.
d. Update the initial guess and solve again until the boundary condition is satisfied.
211

d 2z
 z 1
dx 2
z '(1)  1
z '(3)  3
z  y  1 satisfy this eqaution therefore
2 2
z (1)    1  1
15 15
4 1
z (2)   1  
5 5
8 8
z (3)  2  1  1
15 15

111

y (2)  y (0)
 1  y (0)  y (2)  2
2
y (4)  y (2)
 3  y (4)  6  y (2)
2
y (0)  2 y (1)  y (2)  f (1)   2 y (1)  2 y (2)  2
y (1)  2 y (2)  y (3)  f (2)  y (1)  2 y (2)  y (3)  0
y (2)  2 y (3)  y (4)  f (3)  2 y (2)  2 y (3)  6
 2 2 0  y (1)   2 
    
 1 2 1  y (2)    0 
 0 2 2  y (3)   6 
    

3.3 The rows / columns are dependent. Therefore there is an infinite number of
solutions to the problem.

another explanation:

Supposethat  y  is a solution which satisfy :


d2y
 f ( x)
dx 2
y '(1)  1
y '(3)  3
also  Z  y  constant  is a solution
d 2Z d 2 y
  f ( x)
dx 2 dx 2
Z '(1)  y '(1)  1
Z '(3)  y '(3)  3
Spring 2007 (23 pts)

You are required to solve the following differential equation.

dy
 2 x  y
dx
y (0)  1

1. Solve the equation by expanding a 4th order Taylor series to find the function value
at x=0.1.
2. Solve the equation using the explicit Euler method. Find the function value at x=0.1.
Use h  0.05
3. Use the solution from section 1 to estimate the error in the solution in section 2

dy
 2 x  y
dx
y (0)  1

y ''(0) 2 y '''(0) 3 y ''''(0) 4


y ( x)  y (0)  y '(0)  x  x  x  x
2! 3! 4!
y '(0)  1
y ''(0)  2  y '  3
y 3 (0)   y ''  3
y 4 (0)   y 3  3
y (0.1)  1  1 0.1  1.5  0.12  0.5  0.13  0.125  0.14  0.9145125

y (0.05)  1   2  0   1   0.05  0.95


y (0.1)  0.95   2  0.05   0.95    0.05  0.9075

Eestimation  0.9145125   0.9075   7.0125E  3

exact solution
y  3e ^  x  2 x  2
y  0.9145122

Das könnte Ihnen auch gefallen