In the previous Solving higher-order equations with 4 clusters I (no multiple solutions), a program to solve 10th-order equations (no multiple solutions) as shown above using 4 Raspberry Pi4B clusters. I made. (The graph above is drawn with matplotlib 3.3.3) This time it is a sequel or an appendix. However, only one Raspberry Pi 4B is used this time. And last time it was 10th order, but this time we will make a program to solve 100th order equation (no multiple solution).
First of all, we added the ** solution verification ** that was left unfinished last time, and completed the program to solve the tenth-order equation (without multiple solutions). This is a simple judgment method that uses the point where the sign of the y value changes between two points of x (the point that crosses the x-axis) as the solution. Programmatic changes have added faster @jit and 4 core multiprocessing. numba's @jit speeds up just by adding a line of @jit before the simple function written in the original python program attached to Raspberry OS with Desktop. You can use a local list. However, you can use a one-dimensional list, but not a two-dimensional list. Global variables and lists cannot be used. Also, if you are coding at high speed using numpy code, an error will occur. I got a lot of errors while creating the program, but this program can be used with @jit of numba (as of 2021JAN04), local 1D list, append, for loop, if conditional statement, args argument list reception, return result list The function is written with a simple structure of return. See the basic options @njit and multiprocessing in Last for installation details. This program is attached below.
eq-10ji-check-jit-multiprocessing.py
import time
from multiprocessing import Pool
#from numba import njit
#@njit(cache=True)
def calc_2s(i0,R_f,X_init,X_end,A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10):
Ypre=0
totalsXY=[i0]
for x0 in range(int(X_init), int(X_end)+1):
X = x0/R_f
Y = A0+A1*(X)**1+A2*(X)**2+A3*(X)**3+A4*(X)**4+A5*(X)**5+\
A6*(X)**6+A7*(X)**7+A8*(X)**8+A9*(X)**9+A10*(X)**10
if x0==int(X_init):
Ypre=Y
if Ypre * Y > 0:
Ypre=Y
else:
if Y == 0.0:
totalsXY.append(X)
totalsXY.append(Y)
else:
Ypre=Y
totalsXY.append(X)
totalsXY.append(Y)
return totalsXY
def wrapper_func(args):
return calc_2s(*args)
def multi_processing_pool(Args_Lists):
p = Pool(4)
process_XY = p.map(wrapper_func, Args_Lists)
p.close()
return process_XY
if __name__=="__main__":
print(f"pre-cache")
x_Range_to = 12
r_f = 10
f_range = x_Range_to * r_f
a0=1.
a1=0.
a2=0.
a3=0.
a4=0.
a5=0.
a6=0.
a7=0.
a8=0.
a9=0.
a10=0.
ArgsLists= [(i,r_f,i*f_range/4,(i+1)*f_range/4,\
a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) for i in range(4)]
processXY = multi_processing_pool(ArgsLists)
processXY.clear()
print(f"Calculation Start")
x_Range_to = 12
r_f = 1000000
f_range = x_Range_to * r_f
a0 = 3628801.0
a1 =-10628640.0
a2 = 12753576.0
a3 =-8409500.0
a4 = 3416930.0
a5 =-902055.0
a6 = 157773.0
a7 =-18150.0
a8 = 1320.0
a9 =-55.0
a10= 1.0
initial_time=time.time()
ArgsLists= [(i,r_f,i*f_range/4,(i+1)*f_range/4,\
a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) for i in range(4)]
processXY = multi_processing_pool(ArgsLists)
print(f"Calculation Finished")
processXYstr = str(processXY)
processXYstr = processXYstr.replace('[[', '')
processXYstr = processXYstr.replace(']]', '')
processesXYstr=processXYstr.split('], [')
process0XYstr=processesXYstr[0]
process1XYstr=processesXYstr[1]
process2XYstr=processesXYstr[2]
process3XYstr=processesXYstr[3]
process0sXYstr=process0XYstr.split(', ')
process1sXYstr=process1XYstr.split(', ')
process2sXYstr=process2XYstr.split(', ')
process3sXYstr=process3XYstr.split(', ')
if process0sXYstr[0]=='0' or process0sXYstr[0]=='0.0':
ProcessAdatas=process0sXYstr.copy()
elif process1sXYstr[0]=='0' or process1sXYstr[0]=='0.0':
ProcessAdatas=process1sXYstr.copy()
elif process2sXYstr[0]=='0' or process2sXYstr[0]=='0.0':
ProcessAdatas=process2sXYstr.copy()
elif process3sXYstr[0]=='0' or process3sXYstr[0]=='0.0':
ProcessAdatas=process3sXYstr.copy()
if process0sXYstr[0]=='1' or process0sXYstr[0]=='1.0':
ProcessBdatas=process0sXYstr.copy()
elif process1sXYstr[0]=='1' or process1sXYstr[0]=='1.0':
ProcessBdatas=process1sXYstr.copy()
elif process2sXYstr[0]=='1' or process2sXYstr[0]=='1.0':
ProcessBdatas=process2sXYstr.copy()
elif process3sXYstr[0]=='1' or process3sXYstr[0]=='1.0':
ProcessBdatas=process3sXYstr.copy()
if process0sXYstr[0]=='2' or process0sXYstr[0]=='2.0':
ProcessCdatas=process0sXYstr.copy()
elif process1sXYstr[0]=='2' or process1sXYstr[0]=='2.0':
ProcessCdatas=process1sXYstr.copy()
elif process2sXYstr[0]=='2' or process2sXYstr[0]=='2.0':
ProcessCdatas=process2sXYstr.copy()
elif process3sXYstr[0]=='2' or process3sXYstr[0]=='2.0':
ProcessCdatas=process3sXYstr.copy()
if process0sXYstr[0]=='3' or process0sXYstr[0]=='3.0':
ProcessDdatas=process0sXYstr.copy()
elif process1sXYstr[0]=='3' or process1sXYstr[0]=='3.0':
ProcessDdatas=process1sXYstr.copy()
elif process2sXYstr[0]=='3' or process2sXYstr[0]=='3.0':
ProcessDdatas=process2sXYstr.copy()
elif process3sXYstr[0]=='3' or process3sXYstr[0]=='3.0':
ProcessDdatas=process3sXYstr.copy()
process0sXYstr.clear()
process0XYstr=''
process1sXYstr.clear()
process1XYstr=''
process2sXYstr.clear()
process2XYstr=''
process3sXYstr.clear()
process3XYstr=''
ProcessAdatas.pop(0)
ProcessBdatas.pop(0)
ProcessCdatas.pop(0)
ProcessDdatas.pop(0)
answersXY=[]
for i in range(int(len(ProcessAdatas)/2)):
answersXY.append((float(ProcessAdatas[2*i]),\
float(ProcessAdatas[2*i+1])))
for i in range(int(len(ProcessBdatas)/2)):
answersXY.append((float(ProcessBdatas[2*i]),\
float(ProcessBdatas[2*i+1])))
for i in range(int(len(ProcessCdatas)/2)):
answersXY.append((float(ProcessCdatas[2*i]),\
float(ProcessCdatas[2*i+1])))
for i in range(int(len(ProcessDdatas)/2)):
answersXY.append((float(ProcessDdatas[2*i]),\
float(ProcessDdatas[2*i+1])))
print(f"Time :")
print(str(time.time() - initial_time))
print(f"Answers :")
for i in range(len(answersXY)):
print(answersXY[i])
time.sleep(10)
I created a program to solve a 100th order equation (no multiple solution) using only one Raspberry Pi 4B. This time as well, I used a factorization formula whose solution is known in advance. y= (x- 0.950)(x- 0.951)(x- 0.952)(x- 0.953)(x- 0.954)× (x- 0.955)(x- 0.956)(x- 0.957)(x- 0.958)(x- 0.959)× (x- 0.960)(x- 0.961)(x- 0.962)(x- 0.963)(x- 0.964)× (x- 0.965)(x- 0.966)(x- 0.967)(x- 0.968)(x- 0.969)× (x- 0.970)(x- 0.971)(x- 0.972)(x- 0.973)(x- 0.974)× (x- 0.975)(x- 0.976)(x- 0.977)(x- 0.978)(x- 0.979)× (x- 0.980)(x- 0.981)(x- 0.982)(x- 0.983)(x- 0.984)× (x- 0.985)(x- 0.986)(x- 0.987)(x- 0.988)(x- 0.989)× (x- 0.990)(x- 0.991)(x- 0.992)(x- 0.993)(x- 0.994)× (x- 0.995)(x- 0.996)(x- 0.997)(x- 0.998)(x- 0.999)× (x- 1.000)(x- 1.001)(x- 1.002)(x- 1.003)(x- 1.004)× (x- 1.005)(x- 1.006)(x- 1.007)(x- 1.008)(x- 1.009)× (x- 1.010)(x- 1.011)(x- 1.012)(x- 1.013)(x- 1.014)× (x- 1.015)(x- 1.016)(x- 1.017)(x- 1.018)(x- 1.019)× (x- 1.020)(x- 1.021)(x- 1.022)(x- 1.023)(x- 1.024)× (x- 1.025)(x- 1.026)(x- 1.027)(x- 1.028)(x- 1.029)× (x- 1.030)(x- 1.031)(x- 1.032)(x- 1.033)(x- 1.034)× (x- 1.035)(x- 1.036)(x- 1.037)(x- 1.038)(x- 1.039)× (x- 1.040)(x- 1.041)(x- 1.042)(x- 1.043)(x- 1.044)× (x- 1.045)(x- 1.046)(x- 1.047)(x- 1.048)(x- 1.049) = 0
1.00 is 1.00 even if it is raised to the 100th power. 1.00 The number of digits in the integer part above the decimal point does not increase even if the number near the pole is raised to the 100th power. From this, you can use all the significant digits of python's double precision floating point number after the decimal point. This time, I prepared the above 100th order equation. (If the number of digits after the decimal point is too small, on the contrary, the number of digits after the decimal point will be out of the range of the number of digits of the double precision floating point, so I'm not sure if the prepared formula is optimal.)
The program that solves this 100th-order equation is shown below. Except for the peculiarity that the 100th-order equation to be calculated has a solution only in the vicinity of 1.00 poles, the program in the 10th-order equation described above and the program itself are almost the same. (Although the number of variables has increased from 11 in the 10th-order equation to 100 in the 100th-order equation)
eq-100ji-normal.py
import time
from multiprocessing import Pool
#from numba import njit
#@njit(cache=True)
def calc_2s(i0,x_Range_from,R_f,X_init,X_end,\
A0, A1, A2, A3, A4, A5, A6, A7, A8, A9,\
A10,A11,A12,A13,A14,A15,A16,A17,A18,A19,\
A20,A21,A22,A23,A24,A25,A26,A27,A28,A29,\
A30,A31,A32,A33,A34,A35,A36,A37,A38,A39,\
A40,A41,A42,A43,A44,A45,A46,A47,A48,A49,\
A50,A51,A52,A53,A54,A55,A56,A57,A58,A59,\
A60,A61,A62,A63,A64,A65,A66,A67,A68,A69,\
A70,A71,A72,A73,A74,A75,A76,A77,A78,A79,\
A80,A81,A82,A83,A84,A85,A86,A87,A88,A89,\
A90,A91,A92,A93,A94,A95,A96,A97,A98,A99):
totalsXY=[i0]
Ypre=0
for x0 in range(int(X_init), int(X_end)+1):
X = x_Range_from + (x0/R_f)
Y = (X -A0)*(X -A1)*(X -A2)*(X -A3)*(X -A4)*\
(X -A5)*(X -A6)*(X -A7)*(X -A8)*(X -A9)*\
(X-A10)*(X-A11)*(X-A12)*(X-A13)*(X-A14)*\
(X-A15)*(X-A16)*(X-A17)*(X-A18)*(X-A19)*\
(X-A20)*(X-A21)*(X-A22)*(X-A23)*(X-A24)*\
(X-A25)*(X-A26)*(X-A27)*(X-A28)*(X-A29)*\
(X-A30)*(X-A31)*(X-A32)*(X-A33)*(X-A34)*\
(X-A35)*(X-A36)*(X-A37)*(X-A38)*(X-A39)*\
(X-A40)*(X-A41)*(X-A42)*(X-A43)*(X-A44)*\
(X-A45)*(X-A46)*(X-A47)*(X-A48)*(X-A49)*\
(X-A50)*(X-A51)*(X-A52)*(X-A53)*(X-A54)*\
(X-A55)*(X-A56)*(X-A57)*(X-A58)*(X-A59)*\
(X-A60)*(X-A61)*(X-A62)*(X-A63)*(X-A64)*\
(X-A65)*(X-A66)*(X-A67)*(X-A68)*(X-A69)*\
(X-A70)*(X-A71)*(X-A72)*(X-A73)*(X-A74)*\
(X-A75)*(X-A76)*(X-A77)*(X-A78)*(X-A79)*\
(X-A80)*(X-A81)*(X-A82)*(X-A83)*(X-A84)*\
(X-A85)*(X-A86)*(X-A87)*(X-A88)*(X-A89)*\
(X-A90)*(X-A91)*(X-A92)*(X-A93)*(X-A94)*\
(X-A95)*(X-A96)*(X-A97)*(X-A98)*(X-A99)
if x0==int(X_init):
Ypre=Y
if Ypre * Y > 0:
Ypre=Y
else:
if Y == 0.0:
totalsXY.append(X)
totalsXY.append(Y)
else:
Ypre=Y
totalsXY.append(X)
totalsXY.append(Y)
return totalsXY
def wrapper_func(args):
return calc_2s(*args)
def multi_processing_pool(Args_Lists):
p = Pool(4)
process_XY = p.map(wrapper_func, Args_Lists)
p.close()
return process_XY
if __name__=="__main__":
''' INPUT START '''
x_range_from = 0.9
x_range_to = 1.1
r_f = 2000
a0 = 0.950
a1 = 0.951
a2 = 0.952
a3 = 0.953
a4 = 0.954
a5 = 0.955
a6 = 0.956
a7 = 0.957
a8 = 0.958
a9 = 0.959
a10= 0.960
a11= 0.961
a12= 0.962
a13= 0.963
a14= 0.964
a15= 0.965
a16= 0.966
a17= 0.967
a18= 0.968
a19= 0.969
a20= 0.970
a21= 0.972
a22= 0.972
a23= 0.973
a24= 0.974
a25= 0.975
a26= 0.976
a27= 0.977
a28= 0.978
a29= 0.979
a30= 0.980
a31= 0.981
a32= 0.982
a33= 0.983
a34= 0.984
a35= 0.985
a36= 0.986
a37= 0.987
a38= 0.988
a39= 0.989
a40= 0.990
a41= 0.991
a42= 0.992
a43= 0.993
a44= 0.994
a45= 0.995
a46= 0.996
a47= 0.997
a48= 0.998
a49= 0.999
a50= 1.000
a51= 1.001
a52= 1.002
a53= 1.003
a54= 1.004
a55= 1.005
a56= 1.006
a57= 1.007
a58= 1.008
a59= 1.009
a60= 1.010
a61= 1.011
a62= 1.012
a63= 1.013
a64= 1.014
a65= 1.015
a66= 1.016
a67= 1.017
a68= 1.018
a69= 1.019
a70= 1.020
a71= 1.021
a72= 1.022
a73= 1.023
a74= 1.024
a75= 1.025
a76= 1.026
a77= 1.027
a78= 1.028
a79= 1.029
a80= 1.030
a81= 1.031
a82= 1.032
a83= 1.033
a84= 1.034
a85= 1.035
a86= 1.036
a87= 1.037
a88= 1.038
a89= 1.039
a90= 1.040
a91= 1.041
a92= 1.042
a93= 1.043
a94= 1.044
a95= 1.045
a96= 1.046
a97= 1.047
a98= 1.048
a99= 1.049
''' INPUT END '''
print(f"Calculation Start")
initial_time=time.time()
f_range = (x_range_to - x_range_from) * r_f
ArgsLists= [(i,x_range_from,r_f,i*f_range/4,(i+1)*f_range/4,\
a0, a1, a2, a3, a4, a5, a6, a7, a8, a9,\
a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,\
a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,\
a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,\
a40,a41,a42,a43,a44,a45,a46,a47,a48,a49,\
a50,a51,a52,a53,a54,a55,a56,a57,a58,a59,\
a60,a61,a62,a63,a64,a65,a66,a67,a68,a69,\
a70,a71,a72,a73,a74,a75,a76,a77,a78,a79,\
a80,a81,a82,a83,a84,a85,a86,a87,a88,a89,\
a90,a91,a92,a93,a94,a95,a96,a97,a98,a99) for i in range(4)]
processXY = multi_processing_pool(ArgsLists)
print(f"Calculation Finished")
processXYstr = str(processXY)
processXYstr = processXYstr.replace('[[', '')
processXYstr = processXYstr.replace(']]', '')
processesXYstr=processXYstr.split('], [')
process0XYstr=processesXYstr[0]
process1XYstr=processesXYstr[1]
process2XYstr=processesXYstr[2]
process3XYstr=processesXYstr[3]
if process0XYstr[0]=='0' or process0XYstr[0]=='0.0':
process0sXYstr=process0XYstr.split(', ')
elif process1XYstr[0]=='0' or process1XYstr[0]=='0.0':
process0sXYstr=process1XYstr.split(', ')
elif process2XYstr[0]=='0' or process2XYstr[0]=='0.0':
process0sXYstr=process2XYstr.split(', ')
elif process3XYstr[0]=='0' or process3XYstr[0]=='0.0':
process0sXYstr=process3XYstr.split(', ')
if process0XYstr[0]=='1' or process0XYstr[0]=='1.0':
process1sXYstr=process0XYstr.split(', ')
elif process1XYstr[0]=='1' or process1XYstr[0]=='1.0':
process1sXYstr=process1XYstr.split(', ')
elif process2XYstr[0]=='1' or process2XYstr[0]=='1.0':
process1sXYstr=process2XYstr.split(', ')
elif process3XYstr[0]=='1' or process3XYstr[0]=='1.0':
process1sXYstr=process3XYstr.split(', ')
if process0XYstr[0]=='2' or process0XYstr[0]=='2.0':
process2sXYstr=process0XYstr.split(', ')
elif process1XYstr[0]=='2' or process1XYstr[0]=='2.0':
process2sXYstr=process1XYstr.split(', ')
elif process2XYstr[0]=='2' or process2XYstr[0]=='2.0':
process2sXYstr=process2XYstr.split(', ')
elif process3XYstr[0]=='2' or process3XYstr[0]=='2.0':
process2sXYstr=process3XYstr.split(', ')
if process0XYstr[0]=='3' or process0XYstr[0]=='3.0':
process3sXYstr=process0XYstr.split(', ')
elif process1XYstr[0]=='3' or process1XYstr[0]=='3.0':
process3sXYstr=process1XYstr.split(', ')
elif process2XYstr[0]=='3' or process2XYstr[0]=='3.0':
process3sXYstr=process2XYstr.split(', ')
elif process3XYstr[0]=='3' or process3XYstr[0]=='3.0':
process3sXYstr=process3XYstr.split(', ')
process0sXYstr.pop(0)
process1sXYstr.pop(0)
process2sXYstr.pop(0)
process3sXYstr.pop(0)
answersXY=[]
for i in range(int(len(process0sXYstr)/2)):
answersXY.append((float(process0sXYstr[2*i]),\
float(process0sXYstr[2*i+1])))
for i in range(int(len(process1sXYstr)/2)):
answersXY.append((float(process1sXYstr[2*i]),\
float(process1sXYstr[2*i+1])))
for i in range(int(len(process2sXYstr)/2)):
answersXY.append((float(process2sXYstr[2*i]),\
float(process2sXYstr[2*i+1])))
for i in range(int(len(process3sXYstr)/2)):
answersXY.append((float(process3sXYstr[2*i]),\
float(process3sXYstr[2*i+1])))
print(f"Time :")
print(str(time.time() - initial_time))
print(f"Answers :")
for i in range(len(answersXY)):
print(answersXY[i])
time.sleep(10)
When the above program is executed, 100 solutions + 100 candidates will be lined up. The following figure is a graph of this 100th-order equation drawn by matplotlib. matplotlib can easily draw even 100th-order equations. You can see that the upper graph crosses the x-axis at 0.950 and 1.050. The middle looks straight. There should be 100 solutions, but I don't know what. The lower graph is an enlargement of the y-axis. By repeating the vertical movement across the x-axis, x = 1.000 is approaching 0 as much as possible. It certainly crosses the x-axis 100 times. matplotlib is a program like the one below at the stage of the first drawing.
eq-100ji-plot-zoom.py
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0.949, 1.051, 1000)
y = (x-0.950)*(x-0.951)*(x-0.952)*(x-0.953)*(x-0.954)*(x-0.955)*(x-0.956)*(x-0.957)*(x-0.958)*(x-0.959)*\
(x-0.960)*(x-0.961)*(x-0.962)*(x-0.963)*(x-0.964)*(x-0.965)*(x-0.966)*(x-0.967)*(x-0.968)*(x-0.969)*\
(x-0.970)*(x-0.971)*(x-0.972)*(x-0.973)*(x-0.974)*(x-0.975)*(x-0.976)*(x-0.977)*(x-0.978)*(x-0.979)*\
(x-0.980)*(x-0.981)*(x-0.982)*(x-0.983)*(x-0.984)*(x-0.985)*(x-0.986)*(x-0.987)*(x-0.988)*(x-0.989)*\
(x-0.990)*(x-0.991)*(x-0.992)*(x-0.993)*(x-0.994)*(x-0.995)*(x-0.996)*(x-0.997)*(x-0.998)*(x-0.999)*\
(x-1.000)*(x-1.001)*(x-1.002)*(x-1.003)*(x-1.004)*(x-1.005)*(x-1.006)*(x-1.007)*(x-1.008)*(x-1.009)*\
(x-1.010)*(x-1.011)*(x-1.012)*(x-1.013)*(x-1.014)*(x-1.015)*(x-1.016)*(x-1.017)*(x-1.018)*(x-1.019)*\
(x-1.020)*(x-1.021)*(x-1.022)*(x-1.023)*(x-1.024)*(x-1.025)*(x-1.026)*(x-1.027)*(x-1.028)*(x-1.029)*\
(x-1.030)*(x-1.031)*(x-1.032)*(x-1.033)*(x-1.034)*(x-1.035)*(x-1.036)*(x-1.037)*(x-1.038)*(x-1.039)*\
(x-1.040)*(x-1.041)*(x-1.042)*(x-1.043)*(x-1.044)*(x-1.045)*(x-1.046)*(x-1.047)*(x-1.048)*(x-1.049)
plt.plot([0.949,1.051],[0,0],C="Gray")
plt.plot(x, y,C="Red")
plt.ylim([-2e-171,2e-171])
plt.xlim([0.949,1.051])
plt.xlabel('x')
plt.ylabel('y')
plt.title("Zoom up y axis")
plt.show()
This special algebraic equation, which has a solution only near 1.00, could be solved by the Raspberry Pi python program, even if it was a 100th order equation.
Thank you for watching until the end.
Unfortunately, I couldn't create a program for the higher-order equations with multiple solutions that I had planned for the next time, so I canceled it. I'm also looking for other themes and trying to program with python on Raspberry Pi.
This time, I agree with the purpose of Qiita and post it, so you are free to copy or modify the published program. There are no copyright issues.
However, when using the Raspberry Pi 4B, a particularly large heat sink is required for the CPU. In the case of this program, where LAN communication is infrequent, the LAN chip does not get hot. However, if the calculation time continues, a considerable amount of power is used as can be seen from the intense heat generated by the CPU. The small black chip behind the power USB C type also gets hot, so you also need a fan flow.