Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The code:

var('t y z')
P = desolve_system_rk4( [ z, 0.005 * exp(-y/8000) * z^2 - 10]
                        , [y,z]
                        , ics = [ 0, 32000, 0 ]
                        , ivar=t
                        , end_points=400 )
Q = [ (t1,z1) for t1,y1,z1 in P ]

for k in xrange( 1, len(Q)-1 ):
    k1, k2, k3 = k-1, k, k+1
    (t1,z1), (t2,z2), (t3,z3) = Q[k1], Q[k2], Q[k3]

    if z1 <= z2 and z2 >= z3:
        print "( %s, %s ) is a local MAX" % ( t2, z2 )
    if z1 >= z2 and z2 <= z3:
        print "( %s, %s ) is a local MIN" % ( t2, z2 )
    if z1 <= 0 and z2 >=0:
        print "ZERO BETWEEN ( %s, %s ) and ( %s, %s )" % ( t1, z1, t2, z2 )

finds...

( 37.8, -231.6456047650853 ) is a local MIN

but misses of course the known initial zero

sage: Q[0]
(0, 0)

and a possible zero at the end of the interval. Bur looking at

sage: Q[-2:]
[(399.9, -36.4642141232692), (400.0, -36.4558355793491)]

we see there is no zero at the other end of the interval.

The code:

var('t y z')
P = desolve_system_rk4( [ z, 0.005 * exp(-y/8000) * z^2 - 10]
                        , [y,z]
                        , ics = [ 0, 32000, 0 ]
                        , ivar=t
                        , end_points=400 )
Q = [ (t1,z1) for t1,y1,z1 in P ]

for k in xrange( 1, len(Q)-1 ):
    k1, k2, k3 = k-1, k, k+1
    (t1,z1), (t2,z2), (t3,z3) = Q[k1], Q[k2], Q[k3]

    if z1 <= z2 and z2 >= z3:
        print "( %s, %s ) is a local MAX" % ( t2, z2 )
    if z1 >= z2 and z2 <= z3:
        print "( %s, %s ) is a local MIN" % ( t2, z2 )
    if z1 <= 0 and z2 >=0:
        print "ZERO BETWEEN ( %s, %s ) and ( %s, %s )" % ( t1, z1, t2, z2 )
    if z1 >= 0 and z2 <=0:
        print "ZERO BETWEEN ( %s, %s ) and ( %s, %s )" % ( t1, z1, t2, z2 )    # EDITED HERE, sorry

finds...

ZERO BETWEEN ( 0, 0 ) and ( 0.1, -0.9999969473920776 )
( 37.8, -231.6456047650853 ) is a local MIN

but misses of course the known initial zero

sage: Q[0]
(0, 0)

and a possible zero at the end of the interval. Bur looking at

sage: Q[-2:]
[(399.9, -36.4642141232692), (400.0, -36.4558355793491)]

we see there is no zero at the other end of the interval.