Homework Set No. 10
1. Linear Shooting Method for a two-point boundary value problem
Consider the dierential equation
y = y + 2y + cos(x),
0x
,
2
with boundary conditions
y ( ) = 0.1.
2
y (0) = 0.3,
Note that the exact solution is given as
y (x) = (sin(x)
Polynomial interpolation: simplest version
> X = [1,0,0;1,1,1;1,2/3,4/9]
% van der Monde matrix
X =
1.0000
0
0
1.0000
1.0000
1.0000
1.0000
0.6667
0.4444
> y = [1;0;1/2]
y =
1.0000
0
0.5000
> a = X\y
a =
1.0000
-0.2500
-0.7500
SCE/MATH 451, Numerical Compu
Taylor series methods
Example:
x = x + et ,
x(0) = 0
Exact solution: x(t) = tet .
0.4
x(t) (eksakt)
m=1 (Euler)
m=2
0.35
0.3
0.25
0.2
0.15
0.1
0.05
0
0
0.5
1
1.5
t
SCE/MATH 451, Numerical Computations
2
2.5
3
1
Taylor series methods
Another example:
x = x
Systems of linear equations
Our Matlab function for naive Gaussian
elimination looks like this:
function x = naiv_gauss(A,b);
n = length(b); x = zeros(n,1);
for k=1:n-1 % forward elimination
for i=k+1:n
xmult = A(i,k)/A(k,k);
for j=k+1:n
A(i,j) = A(i,j)-x
Natural cubic spline
Computing zi :
function z = cspline(t,y)
n = length(t);
z = zeros(n,1);
h = zeros(n-1,1);
b = zeros(n-1,1);
u = zeros(n,1);
v = zeros(n,1);
h = t(2:n)-t(1:n-1);
b = (y(2:n)-y(1:n-1)./h;
u(2) = 2*(h(1)+h(2);
v(2) = 6*(b(2)-b(1);
for i=
Eective programming
Next example shows three dierent ways of
computing an inner product of two vectors.
zi = xi yi ,
i = 1, 2, . . . , n
Method 1:
Do not allocate memory space for z in advance.
Compute the elements in the new vector by a
for-loop.
x = ran
Homework Set No. 9
1. Scalar ODE
Consider the following ordinary dierential equation:
x = 2x2 + x 1,
x(1) = 1.
(a) Write out the Eulers method for this ODE. Compute the value x(1.2) by Eulers
method, with h = 0.1.
(b) Write out the Heuns method for this O
MATLAB
MATLAB is an advanced program package tool
for numerical computation og visualization.
Advantages:
easy to use and program.
can be run interactively or from a le.
2- and 3-dimensional plot.
many built-in numerical functions.
can be developed w
Homework Set No. 8
1. Simplest problem using least squares method
Use the method of least squares, nd the constant function that best ts the data
x
y
-1
5/4
2
4/3
3
5/12
2. The method of least squares with polynomial regression
(a) What straight line best
Homework Set No. 7
1. Various methods
The linear system
4 x1 + 3 x2
=
24
3 x1 + 4 x2
x3 =
30
x2 + 4 x3 = 24
should be solved by the following methods (do not use Matlab for this problem)
a) Gaussian elimination (tridiagonal system).
b) Jacobis method.
c)
2
Homework Set No. 2
NB! If a problem is not specied to use Matlab, then you should not use Matlab.
Preparation for Matlab home works: Read chapter 3 in the notes of Gockenbach.
Problem 1
(a). The Taylor series for (1 + x)n is also known as the binomial s
Homework Set No. 4
The problems will be graded selectively.
NB! Problems marked with (*) are more challenging, extra points will be awarded for
them. For that reason, no hints will be given for those problems before the due date.
1. Trapezoid and Simpsons
3
Homework Set No. 3
Problem 1.
Determine whether this function is a rst-degree spline:
1 x 0.5
x
S (x) =
0.5 + 2(x 0.5)
0.5 x 2
x + 1.5
2x4
Problem 2.
1
Show that f (x) p(x) = 2 f ( )(x a)(x b) for some in the interval (a, b), where p
is a linear polynom
Homework Set No. 5, Numerical Computation
1. Bisection method
We consider the bisection method to nd a root for f (x) = 0. If f (0) < 0 and f (1) > 0,
then there is a root on the interval [0, 1], and we take [0, 1] as the initial interval. How
many steps