Mathedu Courses logo

Mathedu Courses

If you see this, something is wrong

Table of contents

First published on Wednesday, Sep 2, 2026 and last modified on Thursday, Sep 3, 2026

Lecture 5 - Application to Astronomy

Fabienne Chaplais Email

1 Lecture 5

from numpy import *
from numpy.linalg import *
from matplotlib.pyplot import *
# Distances of the planets to the sun in AUs
Dist=array([0.387,0.723,1.0,1.523,5.203,9.541])

# Coefficients matrix
A=array([[1.0,Dist[0],Dist[0]**2],
         [1.0,Dist[1],Dist[1]**2],
         [1.0,Dist[2],Dist[2]**2]])
print('The coefficients matrix is A=\n',A)
# Periods of the planets in years
Period=array([0.241,0.615,1.0,1.881,11.861,29.457])

# Second members column vector
B=array([[Period[0]],[Period[1]],[Period[2]]])
print('The second members column vector is B=\n',B)
# The polynomial that fits the first three planets data
a=solve(A,B)
a0=a[0,0]
a1=a[1,0]
a2=a[2,0]
print('The polynomial is P(x)=\n',a0,'+',a1,'x +',a2,'x^2')
# Visualisation
x=arange(0,2,0.01)
y=a0+a1*x+a2*x**2 
plot(x,y,label='Polynomial')
# Mercury
plot(Dist[0],Period[0],'ko',markersize=3)
# Venus
plot(Dist[1],Period[1],'ko',markersize=3)
# Earth
plot(Dist[2],Period[2],'ko',markersize=3)
grid()
legend()
# Check
# Mars
plot(Dist[3],Period[3],'ko',markersize=3)
P_of_Mars=a0+a1*Dist[3]+a2*Dist[3]**2 
print('The error for Mars is ',Period[3]-P_of_Mars)
# Jupiter
P_of_Jupiter=a0+a1*Dist[4]+a2*Dist[4]**2 
print('The error for Jupiter is ',Period[4]-P_of_Jupiter)
# Saturn
P_of_Saturn=a0+a1*Dist[5]+a2*Dist[5]**2 
print('The error for Saturn is ',Period[5]-P_of_Saturn)
# Fitting the natural logarithms with a straight line
LnDist=log(Dist)
LnPeriod=log(Period)
X=arange(-2,4,0.01)
Y=(3/2)*X

figure()
plot(X,Y,label='The straight line')
# Mercury
plot(LnDist[0],LnPeriod[0],'ko',markersize=3)
# Venus
plot(LnDist[1],LnPeriod[1],'ko',markersize=3)
# Earth
plot(LnDist[2],LnPeriod[2],'ko',markersize=3)
# Mars
plot(LnDist[3],LnPeriod[3],'ko',markersize=3)
# Jupiter
plot(LnDist[4],LnPeriod[4],'ko',markersize=3)
# Saturn
plot(LnDist[5],LnPeriod[5],'ko',markersize=3)

grid()
legend()

Discussion: login to participate.