Mathedu Courses logo

Mathedu Courses

If you see this, something is wrong

Table of contents

First published on Thursday, Sep 3, 2026 and last modified on Saturday, Sep 5, 2026

Lecture 6 - Discover the Systems of Linear Equations

Fabienne Chaplais Email

1 Introduction

2 Solution of Some Systems

from numpy import *
from matplotlib.pyplot import *
	
×=arange(-100,2000,100)
y1=x-800
y2=1000-x
	
plot(x,y1,'b',label='Equation1')
plot (x,y2, 'r', label= 'Equation 2')
plot(900,100, 'ko', markersize=5, label=' Solution')
	
legend()
grid()
\[ \begin{matrix} P(1)&=&a_0+a_1\times 1+a_2\times 1^2&=&a_0+a_1+a_2\\ P(2)&=&a_0+a_1\times 2+a_2\times 2^2&=&a_0+2a_1+4a_2\\ P(3)&=&a_0+a_1\times 3+a_2\times 3^2&=&a_0+3a_1+9a_2 \end{matrix} \]
\[ \left\{ \begin{matrix} a_0&+&a_1&+&a_2&=&4\\ &&a_1&+&3a_2&=&-4\\ &&2a_1&+&8a_2&=&8 \end{matrix} \right. \]
\[ \left\{ \begin{matrix} a_0&+&a_1&+&a_2&=&4\\ &&a_1&+&3a_2&=&-4\\ &&&&2a_2&=&16 \end{matrix} \right. \]
from numpy import *
from matplotlib.pyplot import *
	
x=arange(-2,6,0.01)
y=24-28*X+8****2
	
plot(x,y,'b',label='$y=24-28x+x^2$')
	
plot(1,4, 'ko',markersize=5)
plot(2,0, 'ko',markersize=5)
plot(3,12, 'ko',markersize=5)
	
grid()
legend(

3 The Matrix View

\[ \left\{ \begin{matrix} x&-&y&=&800\\ x&+&y&=&1,000 \end{matrix} \right. \]
\[ \overline{A}=\begin{bmatrix} a_{00}&a_{01}&…&a_{0,n-1}&b_{0}\\ a_{10}&a_{11}&…&a_{1,n-1}&b_{1}\\ \vdots&\vdots& &\vdots&\vdots\\ a_{m-1,0}&a_{m-1,1}&…&a_{m-1,n-1}&b_{m-1}\\ \end{bmatrix} \]

4 Solve a Square Matrix Equation in Python (1)

from numpy import *
from numpy.linalg import *
from matplotlib.pyplot import *
	
A=random.randn(10,10)
imshow(A)
title('coefficients matrix A')
	
B=random.randn(10,1)
X=solve(A,B)
	
figure()
	
subplot(1,2,1)
imshow(B)
title('second members B')
	
subplot(1,2,2)
imshow(A@X)
title('product AX')

5 Application to Astronomy

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 coeeficients 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 three first planets data
a=solve(A,B)
a0=a[0,0]
a1=a[1,0]
a2=a[2,0]
print('The polynomial is\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='the parabola')
# 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()

6 Conclusion

Discussion: login to participate.