hw6_solS09

hw6_solS09 - EE 103, Spring '09, Prof SEJ: HW 6 Sol....

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
EE 103, Spring ’09, Prof SEJ: HW 6 Sol. Applied Numerical Computing Instructor: Prof. S. E. Jacobsen HW 6 Solution Students: Distributed HW solutions are a component of the course and should be fully understood. Prob 1: (a) function [f J]= hw6p1(x,u,v) %Given x,u,v, the function returns the vector f and its Jacobian J for k=1:length(u) f(k)=x(1)*exp(-x(2)*u(k))-v(k); end f=f'; J=hw6p1jac(x,u,v); % function [J] = hw6p1jac(x,u,v) for k=1:length(u) J(k,:)=[exp(-x(2)*u(k)), -x(1)*u(k)*exp(-x(2)*u(k))]; end %initial x x=[14.55, 0.0683]'; %begin Gauss-Newton [f J]=hw6p1(x,u,v) f = -3.2293 -1.5950 -0.3668 1.2661 1.5717 1.5338 0.3025 -0.7217 J = 0.9533 -9.7095 0.9213 -16.0861 0.9026 -19.6998 0.8430 -30.6653 0.7609 -44.2867 0.6415 -60.6696 0.4881 -74.5758 0.3353 -78.0523
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
EE 103, Spring ’09, Prof SEJ: HW 6 Sol. %compute G-N direction,the amount to add to x y=(J'*J)\(-J'*f) y = 1.1538 0.0178 %increment x x=x+y x = 15.7038 0.0861 %next iteration [f J]=hw6p1(x,u,v) f = -2.3146 -0.8375 0.3014 1.6630 1.6289 1.1740 -0.4403 -1.6390 J = 0.9415 -10.3498 0.9019 -16.9950 0.8789 -20.7021 0.8064 -31.6574 0.7087 -44.5157 0.5715 -58.3308 0.4050 -66.7764 0.2522 -63.3755 y=(J'*J)\(-J'*f) y = 0.1897 0.0039 x=x+y x = 15.8935 0.0900 %next iteration [f J]=hw6p1(x,u,v) f = -2.1773 -0.7342 0.3857 1.6901 1.5869 1.0523 -0.6249 -1.8366
Background image of page 2
EE 103, Spring ’09, Prof SEJ: HW 6 Sol. J = 0.9389 -10.4459 0.8976 -17.1190 0.8737 -20.8285 0.7984 -31.7252 0.6976 -44.3476 0.5570 -57.5397 0.3885 -64.8387 0.2368 -60.2145 y=(J'*J)\(-J'*f) y = 0.0337 0.0008 x=x+y x = 15.9273 0.0908 %next iteration [f J]=hw6p1(x,u,v) f = -2.1539 -0.7176 0.3985 1.6917 1.5750 1.0252 -0.6634 -1.8764 J = 0.9384 -10.4622 0.8967 -17.1389 0.8726 -20.8477 0.7969 -31.7292 0.6954 -44.3002 0.5541 -57.3636 0.3853 -64.4342 0.2338 -59.5769 y=(J'*J)\(-J'*f) y = 0.0065 0.0002 x=x+y x = 15.9337 0.0910 %next iteration [f J]=hw6p1(x,u,v) f = -2.1495 -0.7144 0.4009 1.6919 1.5727 1.0199 -0.6709 -1.8841
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
EE 103, Spring ’09, Prof SEJ: HW 6 Sol. J = 0.9383 -10.4654 0.8966 -17.1427 0.8724 -20.8513 0.7965 -31.7298 0.6949 -44.2907 0.5535 -57.3291 0.3847 -64.3557 0.2332 -59.4537 y=(J'*J)\(-J'*f) y = 0.0012 0.0000 x=x+y x = 15.9350 0.0910 %next iteration [f J]=hw6p1(x,u,v) f = -2.1486 -0.7138 0.4014 1.6919 1.5722 1.0188 -0.6723 -1.8856 J = 0.9383 -10.4660 0.8965 -17.1434 0.8724 -20.8520 0.7965 -31.7299 0.6948 -44.2889 0.5534 -57.3225 0.3845 -64.3406 0.2331 -59.4300 y=(J'*J)\(-J'*f) y = 1.0e-003 * 0.2379 0.0057 x=x+y x = 15.9352 0.0910
Background image of page 4
EE 103, Spring ’09, Prof SEJ: HW 6 Sol. %next iteration [f J]=hw6p1(x,u,v) f = -2.1485 -0.7137 0.4015 1.6920 1.5721 1.0187 -0.6726 -1.8859 J = 0.9383 -10.4661 0.8965 -17.1436 0.8724 -20.8522 0.7965 -31.7299 0.6948 -44.2885 0.5534 -57.3213 0.3845 -64.3377 0.2331 -59.4255 y=(J'*J)\(-J'*f) y = 1.0e-004 * 0.4560 0.0109 x=x+y x = 15.9352 0.0910 %next iteration [f J]=hw6p1(x,u,v) f = -2.1484 -0.7137 0.4015 1.6920 1.5721 1.0186 -0.6727 -1.8860 J = 0.9383 -10.4661 0.8965 -17.1436 0.8724 -20.8522 0.7965 -31.7299 0.6948 -44.2885 0.5534 -57.3210 0.3845 -64.3371 0.2331 -59.4246 y=(J'*J)\(-J'*f) y = 1.0e-005 * 0.8741 0.0210
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
EE 103, Spring ’09, Prof SEJ: HW 6 Sol. x=x+y x = 15.9353 0.0910 %next iteration [f J]=hw6p1(x,u,v) f = -2.1484 -0.7137 0.4015 1.6920 1.5721 1.0186 -0.6727 -1.8860 J = 0.9383 -10.4661 0.8965 -17.1436 0.8724 -20.8522 0.7965 -31.7299 0.6948 -44.2884 0.5534 -57.3210 0.3845 -64.3370 0.2331 -59.4244 y=(J'*J)\(-J'*f) y = 1.0e-005 * 0.1675 0.0040 x=x+y x = 15.9353 0.0910 %next iteration [f J]=hw6p1(x,u,v) f = -2.1484 -0.7137 0.4015 1.6920 1.5721 1.0186 -0.6727 -1.8860 J = 0.9383 -10.4661 0.8965 -17.1436 0.8724 -20.8522 0.7965 -31.7299 0.6948 -44.2884 0.5534 -57.3210 0.3845 -64.3370 0.2331 -59.4244
Background image of page 6
EE 103, Spring ’09, Prof SEJ: HW 6 Sol. y=(J'*J)\(-J'*f) y = 1.0e-006 * 0.3212 0.0077 x=x+y x = 15.9353 0.0910 %stop (b) function [fx gx H]= hw6p1(x,u,v) %Given x,u,v, the function returns f(x), its gradient vector and its Hessian for k=1:length(u) f(k)=x(1)*exp(-x(2)*u(k))-v(k); end f=f'; fx=f'*f; % 0.5*f’*f would be better, but either is OK. J=hw6p1jac(x,u,v); gx=f'*J; gx=gx'; H=hw6p1hes(x,f,J,u,v); function [J] = hw6p1jac(x,u,v) for k=1:length(u) J(k,:)=[exp(-x(2)*u(k)), -x(1)*u(k)*exp(-x(2)*u(k))]; end function H = hw6p1hes(x,f,J,u,v) H=J'*J; for i=1:length(u) H=H+f(i)*[0,-u(i)*exp(-x(2)*u(i)); -u(i)*exp(-x(2)*u(i)), ... x(1)*u(i)^2*exp(-x(2)*u(i))]; end (c) %the x value x=[14.55, 0.0683]'; [fx gx Hx]=NewtonMin('hw6p1', x, 1e-6, u, v) xMin = [ 15.9352540677 0.0910261278 ] f(xMin)= 15.6675175875 Number of iterations=4 Number of Steepest Descent Iterations=0 fx = 15.9353 0.0910 gx = 0.0000 -0.0035
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
EE 103, Spring ’09, Prof SEJ: HW 6 Sol. Hx = 1.0e+004 * 0.0004 -0.0170 -0.0170 1.3290 %note: at each of the four iterations, H was PD. % %new x value x=[10,6]'; [fx gx Hx]=NewtonMin('hw6p1', x, 1e-6, u, v) xMin = [ 15.9352540678 0.0910261278 ] f(xMin)= 15.6675175864 Number of iterations=10 Number of Steepest Descent Iterations=5 fx = 15.9353 0.0910 gx = 0.0000 -0.0012 Hx = 1.0e+004 * 0.0004 -0.0170 -0.0170 1.3290 %note: of the 10 iterations, H was not PD for 5 of them.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/01/2010 for the course EE EE 103 taught by Professor Jacobsen during the Spring '09 term at UCLA.

Page1 / 19

hw6_solS09 - EE 103, Spring '09, Prof SEJ: HW 6 Sol....

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online