Академический Документы
Профессиональный Документы
Культура Документы
f x
f
f x0
n
f x0 x x0
x0 x x0
n!
n 1
x
x
f x
R x
Where
P x
f '' x0 x x0
2!
'
x
n
n 1
x x0
1 !
1, f ' x0
f x
f
'''
21 11 4
x
64 0
x0
f x
1 3 4
x
4 0
1
4
3 7 4
x
16 0
16
21
64
3
1
x1
x1
32
4
, f '' x0
7
x
128
11 4
x1
|f x P x | max
7
.95
128
f x0 h
11 4
7
x
128
1.061
11 4
x1
h2 ''
f x0
2!
hf ' x0
h3 '''
f x0
3!
sin 1
sin x
x
x
2! 3!
, cos x
x
n!
Consider:
f x
, where:
e
f
is a
tanh x
x
y
0.27
1.38
[a,b],
. Consider the
in order to determine an
1
c
2x
1
c
2P
:
Perturbed Data:
f x
xn
1
c or 1 P
2
P
2P
f x
1 0.123
0.123
2
3
24
0.54163 0.34358 O
f x
f xn
f ' xn
xn
xn 3 R
2xn 3 R
xn
xn
xn 1
f x
f x
0.27
0.961
1.23 x
has the exact
1.38
4.89
6.29 y
0.03
1
, whereas the given system has solution
0.196
1
f x
1
cP
is ill conditioned.
given problem
computed solution
0.4629
x 0.123
perturbed problem
f x
x 0.123
and:
a b x
c d y
For example,
With small
Solution:
Almost any perturbation of the 6 constants in the data will do.
Let
solution
x
1.23 x
6.29 y
0.96
4.91
Solution:
| |
system:
mid a, b
then:
f x
exact solution r
,p
Trig Substitution:
Sin(2)=2sin()cos()
sin(a-b)=sin(a)cos(b)-cos(a)sin(b)
cos(a-b)=cos(a)cos(b)+sin(a)sin(b)
cos(2)=cos2()-sin2()=2cos2()-1=1-2sin2()
Rationalization
Taylor approximations:
x
1!
x
h2
sin 1
2
h cos 1
p |
computed solution r
With small
|p
Perturbed Data:
1.360 105
f x0
sin 1
for x close to 0
is small.
x
fl y z for w=16.00, x=43.61, y=12.31,
z=56.68
Using idealized, rounding, floating point arithmetic (base 10,
k=4), the above equation evaluates to 0.1. The exact value is
0.0292. Use the definition of stability to show (by using only a
perturbation in y) that the computation is stable.
Solution:
To show that its stable, find a value for which the exact value
of (16.00)(43.61)-(12.31+)(56.68) is approx equal to 1.
in order to
R
xn 2
xn 3 R
xn
xn
3 R
R
x
2x
n
n
2xn
xn 2
3
3
3
R xn
R
2R
2xn
xn
xn
2xn 3 R
2xn 3 R
xn 2
fl fl w
16 43.610.1
0.00125
0.123
12.31
is small, the
b 2
if f c
0, stop
otherwise, a new interval that is half the length
of the previous interval is determined:
o if f a
f c
0 set b c
f c
0 set a c
o if f b
Multiplicity:
m = multiplicity
If m= 1, then p is a simple zero of f(x)
Secant Method:
th
Error in k approx.:
Order of convergence:
f P
p; e
P
P
|e ||e
ax
cn = bn
cn-1 = bn-1+cnx0
c1 = b1+c2x0 = P(x0)
P(x) = (x-x0)Q(x)+b0
Original polynomial: P(x) = anxn+ an-1xn-1+ a1x+a0
Deflated polynomial: Q(x) = b1+b2x2+b3x3+bnxn-1
An approximation to one of the zeros of P(x) = x4 + x3 - 6x2 - 7x 7 is
x0 = 2.64 . If x0 is used as an approximation to a zero of P(x), use
synthetic division (Horner's algorithm) to determine the associated
P x
Mullers Method:
a x
b x
c
b
f x
x
f x
x
f x
x
x
x
f x
x x
x
x f x
x
x x
x
f x
x x
f x
x x
f x
f x
2c
sign b b
4ac
L x
L x
L x
f x
f x
P x
1 x 2
1
2
x x 2
1
1
x x 1
2 1
P x
1,
x x x x
x x
x
x
x x x x
x x
x
x
x x x x
x x
x
x
P x
3, f x
P x
17
3L x
L x
P x
xx1 xx2
x0 x1 x0 x2
y0
xx0 xx2
x1 x0 x1 x2
xx0 xx1
y1
x2 x0 x2 x1
Order of Convergence:
|P
lim
P|
|P
P|
f x k Lk ' x
f' x
n 1
k 0
y2
n 1
xj
xx0
y
x1 x0 1
n 1
x xj
xj
xj xk
n 1 !
k 0, k j
For n = 1, j = 0:
f x
P x
x
1 !
assume f(x)C(n+1)[a,b]
Let P(x) denote the (linear) polynomial of degree 1 that
interpolates f(x) = cos x at the points x0 = -0.1 and x1 =
0.1 (where x is in radians). Use the error term of
polynomial interpolation to determine an upper bound for
|P(x) - f(x)|, where x [-0.1, 0.1] Do not construct P(x).
Solution: |P(x) - f(x)| = |f"()(x-0.1)(x+0.1)/2!| with
0.1< < 0.1
= |-cos()(x2 0.01)/2| <= cos(0)/2 max(-0.1 <= <=
0.1)|x2 0.01| = 0.5 |0 0.01| = 0.005
Runge Phenomenon:
f x
P x
P x for k
f x L , x
f x L
0,1,2 n
f x L
f x
f ' x1
x 1 x2
x0 x 1 x0 x 2
f x0
f x2
where:
x2 x0 x2 x1
x
f
f x
f x
f x1
2x1 x0 x2
x 1 x 0 x1 x 2
x1 x0
f x
where 1 lies
4f x
3f x
x
N h
f x
K h
K h
h
2
f x
2h
x 2h
h
f
2
hf x
for j
h
2
for j
K h
h
2
h
f x
2
f x dx
h
f
12
f x
x , degree = 1
h x
Simpsons Rule (n=2):
h
f x
4f x
3
2, degree = 3
f x dx
h
f
90
f x
f x
f x dx
f x dx
a
1
x
x
x
x
a
6
4
b
a
6
3
b
a
6
2
b
a
6
a
6
1
a
a
a
a
h
f x0
3
4 1 1
4
4f x1
1
2
a b
4
2
a b
4
2
a b
4
2
f x2
b
b
b
a
a
h5
f
90
2
b
a
3
a
4
a
5
h
f
3
h
f
n 1 !
h
f
3
4f
2f
4f
f x dx
f x dx
Where:
f x
f x
1
2h
h
2
Case 2:
xx1
y
x0 x1 0
x
x
x
x
17L x
Polynomial Interpolation:
general form:
P x
x x0 x x1 x xk1 x xk 1 x xn
xk x0 xk x1 xk xk1 xk xk 1 xk xn
Ln,k x
h
f
3
Truncation error:
4f
E
2f
4f
2f
f
4f
2f
4f
Richardsons Extrapolation:
Case 1:
N h
K h
K h
K h
R1,1
R2,1
R3,1
M
R
R2,2
R3,2
M
R3,3
M
f
, where
, where
, where
wi
, where
R2,2
R3,2
R3,3
f x dx
f x dx
S |
If |S
h
f
1440
1
|S
15
15 ,
1
S
15
g t dt
Approximate
Solution:
f x
cg x
5
8
5
f x
f x
f x
9 1 9 2 9 3
1
5cos 0.7745967
8cos 0.0
5cos 0.7745967
f x dx
9 1 0.0
9 1 0.7745967
9 1 0.7745967
2.144494
w
w
y t
h f t ,w
y t
y t
h
x
x
x
a
a
a
f x
f x
f x
m
m
m
a
a
a
a
a
a
,E
m E
,E
m E
,E
m E
a x
if pi
For k=i to n
tempaik
aikapk
apktemp
tempbi
bibp
bptemp
continue with Gaussian.
f t ,w
w
w
w
Forward Elimination:
f x dx
1 x
1 x
1 x
S |
f x dx
t i ,wi , int n 1
R1,1
R2,1
R3,1
n1
hn
f
n!
h2 '
f t i ,wi
2
h f t i ,wi
h
y
n 1 !
h f
wi
f t ,w
max |y
hM L
e
2L
w|
|y
h
|
f t ,y t
h
y
2
h
M,
2
a , x
E A , e b
are small.
Matlab Code:
ezplot(0.5*exp(x/3)-sin(x), [-4, 5] )
fplot( 3*x^3-x-1, [-1 2], - )
fzero to compute the zeros of f(x):
fzero(' 0.5*exp(x/3)-sin(x)', [ -5, -3] )
Change bounds for each interval in which a zero is located.
Polynomial Operations:
The coefficients of a polynomial are stored in a vector p
(starting with the coefficient of the highest power of x).
p(x) = x3 - 2x 5
p = [1 0 -2 -5];
r = roots(p)
Will compute and store all of the roots of the polynomial in r.
Alternate form: r = roots( [1 0 -2 -5] )
If r is any vector, p = poly(r), will result in p being a vector
whose entries are the coefficients of a polynomial p(x)
that has as its roots the entries of r.
Example:
r = [1 2 3 4];
p = poly(r)
Results in p = [1 -10 35 -50 24],
p(x) = x 4 -10x3 + 35x2 - 50x + 24
The function polyval evaluates a polynomial at a
specified value. If p = [1 -10 35 -50 24], then polyval(p, -1)
gives the value of p(x) = x 4 -10x3 + 35x2 - 50x + 24
at x = -1, namely 120. MATLAB uses HORNER'S
ALGORITHM for polyval.
Put with polynewton!!!!!!!!
Polynewton computes one zero of a polynomial. Input
variables: n the polynomial degree a a vector of the
coefficients of the polynomial P(x)
pzero the initial approximation to a zero Nzero the
maximum number of iterations allowed tol relative error
tolerance used to test for convergence and the output
variables are p the final computed approximation to a zero
of P(x) b the final vector of values b computed by Horners
algorithm, from which the deflated polynomial can be
obtained.
polynewton(4, [-3.3 -1 0 2 5], 1.3, 20, 1e-8);
Will output to the screen each computed approximation to
the zero.
[x, y] = polynewton(4, [-3.3 -1 0 2 5], 1.3, 20, 1e-8);
Will output to the screen each computed approximation to a
zero, will store the final computed approximation in the
variable x, and will store the final computed vector of values
b from Horners algorithm in the vector y.
The MATLAB function INTERP1 can be used to do
linear and cubic polynomial interpolation. If X denotes a
vector of values, Y = F(X) a set of corresponding function
values, then z = interp1(X, Y, x) or z = interp1(X, Y, x,
'linear').
z = interp1(X, Y, x, 'cubic') determines z based on a cubic
polynomial approximation.
For the cubic spline with clamped boundary conditions, the
data to be interpolated should be stored in vectors, X and Y,
where Y has 2 more entries than X and the first and last
entries of Y are the two boundary conditions. If S(x)
denotes the cubic spline interpolant, and z is a given
number, then the value of S(z) can be computed by
entering spline(X, Y, z). To determine the coefficients of
the spline, first determine the pp (piecewise polynomial)
form of the spline by entering pp = spline(X, Y). Then enter
[breaks, coefs] = unmkpp(pp). breaks: a vector of the
knots (or nodes) of the spline, coefs: an array, the i-th row
of which contains the coefficients of the i-th spline
Newton.m
To find a zero of the function. Input Initial approx. pzero,
maximum interations Nzero, tolerance tol.
function p = newton(pzero,Nzero,tol)
i=1;
Quad - Numerically evaluate integral, adaptive Simpson
while i <= Nzero
quadrature. Use array operators .*, ./ and .^
-5
p = pzero-f(pzero)/fp(pzero);
using tol = 10
2
fprintf('i = %g',i),fprintf(' approximation = %18.10f\n',p)
sin(1 / x )dx
if abs(1-pzero/p)<tol
0.1
return
[Q, fnc] = quad (@f, 0.1, 2, 10^-5 )
end
function y=f(x)
i=i+1;
y = sin(1./x);
pzero=p;
Horner: to evaluate the polynomial. Input location x0, end
Ode45: is variable stepsize Runge-Kutta method that uses
degree n, coefficients a. Outputs: b = P(x0), c = P(x0)
fprintf('failed to converge in %g',Nzero),fprintf(' iterations\n')
two Runge-Kutta formulas of orders 4 and 5. Solve non-stiff
f.m
differential equations, medium order method.
function [b, c] = horner(x0, n, a)
function y=f(x)
b(n+1)=a(n+1);
y=32*(x-sin(x))-35;
y (t ) = y(t ) 5e t sin(5t ) , y(0) = 1 on [0,3]
c(n+1)=a(n+1);
fp.m
for j = n: -1: 2
function y=f(x)
[t, y] = ode45('f', [0 3], 1)
b(j) = a(j) + b(j+1)*x0;
y=32*(1-cos(x));
function z=f(t,y)
c(j) = b(j) + c(j+1)*x0;
z = -y-5*exp(-t)*sin(5*t);
function [p,b] = polynewton(n, a, pzero, Nzero, tol)
end
i=1;
b(1) = a(1) + b(2)*x0;
while i<=Nzero
Newtons method to find reciprocal Matlab version of Newtons method for computing 1/R
[b, c] = horner(pzero, n, a);
p = pzero - b(1)/c(2);
1
f ( x) = R
function p = reciprocal(R,pzero,Nzero,tol)
fprintf('i = %g',i),fprintf(' approximation = %18.10f\n',p)
x
i=1;
if abs(1-pzero/p)<tol
1
while
i<=Nzero
f ( x) = 2
return
x
p=2*pzero-R*pzero*pzero;
end
fprintf('i = %g',i),fprintf(' approximation = %18.10f\n',p)
i=i+1;
f ( p0 )
y(i)=p;
pzero=p;
p = p0
if abs(1-pzero/p)<tol
f ( p0 )
End
return
1
fprintf('failed to converge in %g',Nzero),fprintf(' iterations\n')
R
end
p
p = p0 0
i=i+1;
1
pzero=p;
p02
end
fprintf('failed to converge in %g',Nzero),fprintf(' iterations\n')
p = p0 + p0 R p02
p = 2 p0 R p02