Download presentation

Presentation is loading. Please wait.

Published byStephan Rho Modified about 1 year ago

1
Lecture 14: Newton’s method for system of two nonlinear equations Function newton2d01 Set initial (x,y) point, maximum number of iterations, and convergence tolerance. for i= 1:maxiter Perform Newton update; check for convergence; print iterates end Define functions f1(x,y), and f2(x,y) and Jacobian matrix: Jacob(x,y). Download newton2d01.m

2
function newton2d01 %solution of system of two nonlienar equations % f1(x,y) = exp(x)*y = 0 % f2(x,y) = x*cos(y) = 0 % using a Newton iteration. Calls function f1 and f2 and % Jacobian matrix Jacob. % % Setup x = 0.2; y =.5; %initial point (x0,y0) maxiter = 25; %maximum number of iterations tol = 1.e-6; % tolerance (backward error goal) err = inf; iter = 0; disp(['Iteration number = ',num2str(iter),' x=',num2str(x),' y=',num2str(y)]); % Newton update. while err > tol & iter <= maxiter J = Jacob(x,y); rhs = -[f1(x,y);f2(x,y)]; dxy = J\rhs; x = x + dxy(1); y = y + dxy(2); err = norm([f1(x,y);f2(x,y)],Inf); iter = iter+1; disp(['Iteration number = ',num2str(iter),' x=',num2str(x),' y=',num2str(y), ' Backward error=',num2str(err)]); end

3
function z = f1(x,y) z = exp(x)*y; function z = f2(x,y) z = x*cos(y); function xx = Jacob(x,y) %value of Jacobian matrix xx = [exp(x)*y, exp(x); cos(y), -x*sin(y)]; Continue with function newton2d01

4
>> newton2d01 Iteration number = 0 x=0.2 y=0.5 Iteration number = 1 x= y= Backward error= Iteration number = 2 x= y= Backward error= Iteration number = 3 x= e-008 y= e-006 Backward error=3.2121e-006 Iteration number = 4 x=1.6822e-019 y=5.2369e-014 Backward error=5.2369e-014 >>

5
Inclass 1 Modify function newton2d01 to find root of the following nonlinear system: f1(x,y) = sin(y)/(x^2+1) = 0 f2(x,y) = cos(2*y)*sin(x) = 0 For initial point (x0,y0)=(0.4,0.3) and tol=10^(-14)

6
Iteration number = 0 x=0.4 y=0.3 Iteration number = 1 x= y= Backward error= Iteration number = 2 x= y= Backward error= Iteration number = 3 x= y= Backward error= Iteration number = 4 x=1.0521e-011 y=7.0755e-012 Backward error=1.0521e-011 Iteration number = 5 x=0 y=0 Backward error=0

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google