Hi. I have a problem with a physics assignment I have to finish by tonight.
They have already given me a python code, but I have to find the period T of Jupiter through interpolation.
(It doesnt have to be interpolation, but my teacher recommended it.)
This is the program:

from numpy import *
from scitools . easyviz . gnuplot_ import *
# Physical parameters and constants
G = 6.67259 e -11 # Gravitational constant in SI units
yeard = 365.25636 # Number of days in a year
years = yeard *24.0*60.0*60.0 # Number of seconds in a year .
r0 = 1.49597870691 e11 # AU
GMsun = 1.32712440018 e20 # G * M
MsunDivMjup = 1047.3486 # M / m_J
MsunDivMast = 1.0 e23 # M / m_A
# Simulation parameters
time = 50.0 # In years
dt = 0.01 # In years
nstep = int ( round ( time / dt ) )
rJ = zeros (( nstep ,3) , float )
vJ = rJ . copy ()
t = zeros ( nstep , float )
# Initialize positions and velocities in 3 d
rJ [0] = array ([ -5.758295190842140 E +11 ,
-5.704511997951533 E +11 ,1.525358540575477 E +10])
vJ [0] = array ([9.038714838773942 E +03 ,
-8.674265884570330 E +03 , -1.662886596994482 E +02])
# Convert to dimensionless coordinates
rJ = rJ / r0
vJ = vJ * years / r0
#
gmJ = GMsun * years **2.0/ r0 **3.0
gmA = 0.0
for i in range ( nstep -1) :
rJnorm = sqrt ( dot ( rJ [ i ] , rJ [ i ]) )
a = - gmJ * rJ [ i ]/ rJnorm **3.0
vJ [ i +1] = vJ [ i ] + a * dt
rJ [ i +1] = rJ [ i ] + vJ [ i +1]* dt
t [ i +1] = t [ i ] + dt
# Plot
plot ( rJ [: ,0] , rJ [: ,1])
xlabel ( ’X ( AU ) ’) ;
ylabel ( ’Y ( AU ) ’) ;
axis ( ’ equal ’)

I have searched for interpolation via python online, but I can only find interpolation on strings and stuff...
And I have to find the period T, by studying the time between each time Jupiter passes the xz-plane.
I guess this is when the y-coordinate is zero... I tried an if loop to find what i is when rJ =0...
but that didnt really seem to work. Anyone who can help me?

rJ[i,1] is a float and most like never exactly equal to zero, but within a narrow range of zero.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.