```Date: Jun 24, 2013 8:33 AM
Author: Torsten
Subject: Re: Problem with Newton Raphson Method for Two Variables

shubha22@gmail.com wrote in message <5a7b5f15-296b-4133-9502-7cca0508ebf3@googlegroups.com>...> Hello,> >     I have two functions, f1(x1)=a1*exp(b1*x1) > and f2(x2)=a2*exp(-((x2-b2)/c2)^2)> where a1, b1, a2, b2 and c2 are constants. x1 and x2 are dependent variables.> I need to solve the two functions using newton raphson's method. Can anyone help me?> > Thanks> Shubha> > > On Wednesday, October 12, 2011 2:50:30 PM UTC+5:30, Emre  wrote:> > clc,clear> > > > % Newton Raphson solution of two nonlinear algebraic equations> > > > % set up the iteration> > > > error1 = 1.e8;> > > > xx(1) = 0; % initial guesses> > > > xx(2) = 0.5;> > > > iter=0;> > > > maxiter=40> > > > % begin iteration> > > > while error1>1.e-12> > > > iter=iter+1;> > > > x = xx(1);> > > > y = xx(2);> > > > % calculate the functions> > > > f(1) = 4*x^2-20*x+0.25*y^2+8;> > > > f(2) = 0.5*x*y^2+2*x+8;> > > > % calculate the Jacobian> > > > J(1,1) = 8*x-20;> > > > J(1,2) = 0.5*y;> > > > J(2,1) = 0.5*y^2+2;> > > > J(2,2) = x*y;> > > > % solve the linear equations> > > > y = -J\f';> > > > % move the solution, xx(k+1) - xx(k), to xx(k+1)> > > > xx = xx + y';> > > > % calculate norms> > > > error1=sqrt(y(1)^2+y(2)^2);> > > > error(iter)=sqrt(f(1)^2+f(2)^2);> > > > ii(iter)=iter;> > > > if (iter > maxiter)> > > > error1 = 0;> > > > s=sprintf('****Did not converge within %3.0f iterations.****',maxiter);> > > > disp(s)> > > > end> > > > % check if error1 < 1.e-12> > > > end> > > > x = xx(1);> > > > y = xx(2);> > > > f(1) = 4*x^2-20*x+0.25*y^2+8;> > > > f(2) = 0.5*x*y^2+2*x+8;> > > > % print results> > > > f> > > > xx> > > > iter> > > > % plot results> > > > semilogy(ii,error)> > > > xlabel('iteration number')> > > > ylabel('norm of functions')> > > > clear ii> > > > clear error> > > > > > > > what am i doing wrong here, it doesn't converge and find the correct values for x and y? > > > > Is this part> > > > "error1=sqrt(y(1)^2+y(2)^2);> > > > error(iter)=sqrt(f(1)^2+f(2)^2);" right?> > > > Please help me, thanks.Except for trivial cases, both functions f1 and f2 don't have a zero.Moreover, f1 only depends on x1 and f2 only depends on x2.So what exactly are you trying to do with Newton-Raphson ?Best wishesTorsten.
```