<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.6000.16809" name=GENERATOR></HEAD>
<BODY style="MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>Hi,</DIV>
<DIV>I am trying to write a program in python that solves a system of nonlinear equations using newton's method. I don't know what I am doing wrong.&nbsp;Please help</DIV>
<DIV>&nbsp;</DIV>
<DIV>from scipy import*</DIV>
<DIV>&nbsp;</DIV>
<DIV>x = array([0.0,0.0,0.0])<BR>n=len(x)<BR>tol= 0.00001<BR>N=30</DIV>
<DIV>&nbsp;</DIV>
<DIV>k=1<BR>while k &lt;= N:<BR>&nbsp;&nbsp;&nbsp; def f(x):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f= zeros((len(x)),float)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f[0][k]= x[0][k]**2 + x[1][k]-37<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f[1][k]=x[0][k]- x[1][k]**2- 5<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f[2][k]= x[0][k] + x[1][k]+ x[2][k]- 3<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return f[k]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def J(x):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; J= zeros((n,n),float)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for i in range(n):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ei=zeros(n,float)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ei[i]=1.0<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; J[:i]=(f(x[k]+tol*ei)-f(x[k]))/tol<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return J</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y[k] = -(J.I)*f[k]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x[k+1]=x[k]+y[k]</DIV>
<DIV>&nbsp;</DIV>
<DIV>if sqrt(dot(f0,f0)/len(x)) &lt; tol: print x<BR>else:<BR>&nbsp;&nbsp;&nbsp; k=k+1</DIV>
<DIV>&nbsp;</DIV>
<DIV>print 'Too many iterations'<BR></DIV></BODY><font face="Verdana,Arial,Helvetica,Trebuchet MS" size="1">
<br />-- 
<br />This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard.
<br />The full disclaimer details can be found at <a href="http://www.csir.co.za/disclaimer.html">http://www.csir.co.za/disclaimer.html</a>.
<p>
<br />This message has been scanned for viruses and dangerous content by <a href="http://www.mailscanner.info/"><b>MailScanner</b></a>, 
<br />and is believed to be clean.  MailScanner thanks <a href="http://www.transtec.co.uk/">Transtec Computers</a> for their support.
</font>
</HTML>