Answer for assignment 2 (3SK3)

9 downloads 3022 Views 337KB Size Report
Answer for assignment 2 (3SK3). (a). 0. 0. 2. 1. ( , ). [cos. (. )] 2 x x. E k c x kx c dx. +Δ. −Δ. = −. +. Δ. ∫. 0. 0. 0. 0. 1. (cos. ) 0. 1. (cos. ) 0 x x x x. E x kx c xdx k. E.
Answer for assignment 2 (3SK3)  (a)  x +Δ

1 0 [cos x − (kx + c)]2 dx E (k , c) = ∫   2Δ x0 −Δ x0 +Δ

δE 1 =− (cos x − kx − c) xdx = 0 δk Δ x ∫−Δ 0

x0 +Δ

δE 1 (cos x − kx − c)dx = 0 =− δc Δ x ∫−Δ

 

0

x0 +Δ



(cos x) xdx − k

x0 −Δ x0 +Δ



x0 −Δ

x0 +Δ



x dx − c

x0 −Δ

(cos x)dx − k

x0 +Δ



x0 +Δ

2

xdx − c

x0 −Δ



xdx = 0

x0 −Δ x0 +Δ



 

dx = 0

x0 −Δ

Form the above equations, we can see that it is a system of two linear equations in variables k and c 

(b)    K = 3/2*(cos(x0+h)+sin(x0+h)*h‐cos(x0‐h)+sin(x0‐h)*h)/h^3  c= ‐1/2*(‐sin(x0+h)*h^2+3*x0*cos(x0+h)+3*x0*sin(x0+h)*h‐3*x0*cos(x0‐h)+3*x0*sin(x0‐h)*h+sin(x0‐ h)*h^2)/h^3 

(c)  f ( x) = cos x0 − sin x0 ( x − x0 )  

(d)  k*  is not equal to the slope of the linear Taylor expansion. 

(e)  S1 = 

   ‐1/4/h^4*(6*cos(x0+h)*sin(x0+h)*h‐6*sin(x0+h)*cos(x0‐h)*h‐6*cos(x0‐h)*cos(x0+h)+4*sin(x0‐ h)^2*h^2+4*sin(x0+h)^2*h^2+3*cos(x0+h)^2+3*cos(x0‐h)^2+4*sin(x0+h)*sin(x0‐h)*h^2+cos(x0‐ h)*sin(x0‐h)*h^3‐cos(x0+h)*sin(x0+h)*h^3+6*cos(x0+h)*sin(x0‐h)*h‐2*h^4‐6*cos(x0‐h)*sin(x0‐h)*h) 

(f)  They are different, and  g* ( x) = k* x + c*  is a better linear approximation. The reason is  g* ( x) = k* x + c* is the optimal one among all possible linear approximation. 

(g)  The  e( x)  computed based on  g* ( x)  has two roots which are not at  x0 , while its counterpart has only  one root which is at  x0 . The  e( x)  computed based on  g* ( x)  has a local maximum around  x0 , while  the counterpart has the global minimum around  x0 .  The figure  e( x)  computed based on  g* ( x)  when  Δ = π / 4, x0 = 0   s(x)+3485951962931615/10141204801825835211973625643008 x-8109328451921441/900719925 0.2 0.18 0.16 0.14 0.12 0.1 0.08 0.06 0.04 0.02 0 -0.6

-0.4

-0.2

0 x

0.2

0.4

0.6

 

The figure  e( x)  computed based on first order Taylor approximation when  Δ = π / 4, x0 = 0  

1-cos(x) 0.3

0.25

0.2

0.15

0.1

0.05

0 -0.6

-0.4

-0.2

0 x

0.2

0.4

0.6

 

The figure  e( x)  computed based on  g* ( x)  when  Δ = π / 4, x0 = π / 4   abs(cos(x)+1496183387106789/2251799813685248 x-2608639969145111/2251799813685248) 0.16 0.14 0.12 0.1 0.08 0.06 0.04 0.02 0 0

0.5

1 x

1.5

 

The figure  e( x)  computed based on first order Taylor approximation when  Δ = π / 4, x0 = π / 4  

abs(cos(x)-1/2 21/2+1/2 21/2 (x-1/4 π))

0.25

0.2

0.15

0.1

0.05

0 0

0.5

1

1.5

x

 

(h)  n(x 0+h) sin(x 0-h) h2+6 cos(x 0+h) sin(x 0-h) h+6 cos(x 0+h) sin(x 0+h) h+4 sin(x 0-h)2 h2-6 sin(x 0+h) c

0.08 0.06 0.04 0.02 0 -0.02 1.5 1.5

1 1 0.5 x0

0.5 h

 

Matlab Code:   

 

clear; syms x0 h

k

x b real

     

f1 = (cos(x)-k*x-b)*x; term1 = int(f1, x, x0-h, x0+h); f2 = (cos(x)-k*x-b); term2 = int(f2, x, x0-h, x0+h);

       

A = solve(term1, term2, k, b); got

% question (b) k and b are

S1_term = (cos(x) - A.k*x - A.b)^2; S1 = int(S1_term, x, x0-h, x0+h)/(2*h); figure, ezmesh(S1);

% question (e)

% question (h)

                       

S2_term = (cos(x) + sin(x0)*x - cos(x0) - sin(x0)*x0)^2; S2 = int(S2_term, x, x0-h, x0+h)/(2*h); %MSE formula of the first-order Taylor approximation %figure, ezmesh(S2, [pi/200, pi/2, pi/200, pi/2]); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% sub = S2 - S1; %compare the two MSEs on pi/4 and pi/3 sub_1 = subs(sub, x0, pi/4); sub_2 = subs(sub, x0, pi/3); xx = pi/200:pi/200:pi/4; ss = size(xx, 2); ff1 = zeros(1, ss); ff2 = zeros(1, ss); for i=1:ss ff1(i) = subs(sub_1, h, xx(i)); ff2(i) = subs(sub_2, h, xx(i)); end figure, plot(xx, ff1, '-.r*', xx, ff2, '--mo'); xlabel('0 \leq h \leq \pi/4'); ylabel('f(h)'); title('f(h)'); legend('x0=\pi/4', 'x0=\pi/3'); % question (f)

         

% question (g) clear; syms x0 h k x b real f1 = (cos(x)-k*x-b)*x; term1 = int(f1, x, x0-h, x0+h); f2 = (cos(x)-k*x-b); term2 = int(f2, x, x0-h, x0+h); A = solve(term1, term2, k, b); x0_store = [0, pi/4]; h_value = pi/4; for i = 1:2 k = subs(A.k, {h, x0}, {h_value, x0_store(i)}); b = subs(A.b, {h, x0}, {h_value, x0_store(i)}); error1 = abs(cos(x) - k*x - b); figure, ezplot(error1, [x0_store(i)-h_value, x0_store(i)+h_value]); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% apx = cos(x0) - sin(x0)*(x-x0); error_formula = abs(cos(x) - apx); for i = 1:2 error2 = subs(error_formula, x0, x0_store(i)); figure, ezplot(error2, [x0_store(i)-h_value, x0_store(i)+h_value]); end