<HTML><BODY><span style="font-size: 14px; ">Well,<br></span>If F1 is run in Python shell, everything is properly working, BUT if call through the functions it is wrongly answering!!!  <br><span style="font-size: 14px; "><br></span><p>def F1 (const1, x): # const1 should be complex number</p><p>T1=round(2+x+4*x**(1.0/3.0))<br> T2=const1*x<br> T3=const1**2</p><p>x1,x2,x3,x4 = sph_jnyn(T1, x) --> 1-standard function in Python<br> <br> x1=x1[1:] <br> x2=x2[1:]<br> x3=x3[1:]<br> x4=x4[1:]<br> <br> a1=x1+1.0j*x3<br> a2=x2+1.0j*x4</p><p>y1,y2= sph_jn(T1,T2) --> 2- standard function in Python<br> y1=y1[1:]<br> y2=y2[1:]<br> <br> b1=x1+x*x2<br> b2=y1+T2*y2<br> b3=a1+x*a2<br> <br> an1= T3*y1*b1-x1*b2<br> an2= T3*y1*b3-a1*b2<br> a=an1/an2</p><p>bn1= y1*b1-x1*b2<br> bn2= y1*b3-a1*b2<br> b=bn1/bn2</p><p>return a,b</p> <br><br> <br><br><span style="font-size: 14px; ">Четверг, 20 декабря 2012, 20:33  от Dag Sverre Seljebotn <d.s.seljebotn@astro.uio.no>:</span><br>
<blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;" class="mailru-blockquote">
        <div id=""><div class="js-helper js-readmsg-msg">
        <style type="text/css"></style>
        <div id="style_13560320230000000219" class="mr_read__body">
                <base target="_self" href="https://e.mail.ru/cgi-bin/">
                
                        <div id="style_13560320230000000219_BODY"><span style="font-size: 14px; ">On 12/20/2012 07:32 PM, Happyman wrote:</span><br><span style="font-size: 14px; ">>   Hi Python users,</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">> First of all, Marry coming Cristmas!!! ALL THE BEST TO YOU AND YOUR FAMILY</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">> I need solution of integration under trapz() rule:</span><br><span style="font-size: 14px; ">> There are following functions:</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">> def  F1 (const1, x):</span><br><span style="font-size: 14px; ">>        """several calculations depending on bessel</span><br><span style="font-size: 14px; ">> functions(mathematical functions) jn(), yv() exists in Python"""</span><br><span style="font-size: 14px; ">>         return a,b</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">> def   F2(const1 ,const2, D) :</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">>         """Several calculation process"""</span><br><span style="font-size: 14px; ">>          x = D / const2</span><br><span style="font-size: 14px; ">>          [a , b] = F1 ( const1, x)      # Where x - the same as in F1()</span><br><span style="font-size: 14px; ">> function</span><br><span style="font-size: 14px; ">>          S= a*b                               # This is (a*b) just an</span><br><span style="font-size: 14px; ">> example for simply explanation</span><br><span style="font-size: 14px; ">>         return S</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">> def F3(D, R):</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">>        """Here I also calculated some process. So:"""</span><br><span style="font-size: 14px; ">>         return arg1**arg3   # Just for example</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">> def  Integrate_all(const1, const2, min1, step1, max1):</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">>         R=arange(min1, max1, step1)      # This is for function "F3"</span><br><span style="font-size: 14px; ">>         D = arange ( 0.1, 7.0, 0.0001)</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">>         M = zeros ( size(R) )</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">>         for i in range(0,size(R)):</span><br><span style="font-size: 14px; ">>                   M [ i ] = integrate. trapz ( ( F2 ( const1, const2, D</span><br><span style="font-size: 14px; ">> ) * F3 ( D ,R)) , x=D)</span><br><span style="font-size: 14px; ">>        return M</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">>        const1=complex number, const2= float,</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">> The aim of the calculation is to use Integrate_all function for</span><br><span style="font-size: 14px; ">> integration function above!!!!!!!</span><br><span style="font-size: 14px; ">></span><br><span style="font-size: 14px; ">> When I use those functions directly like one by one separately from</span><br><span style="font-size: 14px; ">> python shell it works very accurately, BUT when I do it as shown above :</span><br><span style="font-size: 14px; ">>   ERROR OCCURS:    C:\calculation.py:194: RuntimeWarning: invalid value</span><br><span style="font-size: 14px; ">> encountered in divide!!!!!! (I think this is occuring in F1()) --></span><br><span style="font-size: 14px; ">> bessel functions >>> jn(n,x) and yv(n,x)</span><br><br><span style="font-size: 14px; ">Yet you didn't supply the source code for F1(), so nobody will be able </span><br><span style="font-size: 14px; ">to help you.</span><br><br><span style="font-size: 14px; ">(But what you should do is a) figure out which argument range F1 will be </span><br><span style="font-size: 14px; ">evaluated in ("print const1, x" should get you started if you don't </span><br><span style="font-size: 14px; ">know), b) write a seperate function that *only* evaluates F1 in various </span><br><span style="font-size: 14px; ">points in this range (perhaps plots it etc.). That should probably give </span><br><span style="font-size: 14px; ">you a clue about what you are doing wrong.</span><br><br><span style="font-size: 14px; ">The key is to isolate the problem. That will also help you produce a </span><br><span style="font-size: 14px; ">version of F1 that you feel confident about posting to the list.</span><br><br><span style="font-size: 14px; ">Also, please read</span><br><br><span style="font-size: 14px; "><a href="http://www.catb.org/esr/faqs/smart-questions.html" target="_blank">http://www.catb.org/esr/faqs/smart-questions.html</a></span><br><br><span style="font-size: 14px; ">Dag Sverre</span><br><span style="font-size: 14px; ">_______________________________________________</span><br><span style="font-size: 14px; ">NumPy-Discussion mailing list</span><br><span style="font-size: 14px; "><a href="sentmsg?compose&To=NumPy%2dDiscussion@scipy.org">NumPy-Discussion@scipy.org</a></span><br><span style="font-size: 14px; "><a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a></span><br></div>
                        
                
                <base target="_self" href="https://e.mail.ru/cgi-bin/">
        </div>

        
</div>


</div>
</blockquote>
<br></BODY></HTML>