在Julia上编写程序遇到以下错误:
ERROR: LoadError: syntax: "-2" is not a valid function argument name
代码如下:
tic()
using JPLEphemeris
using SatelliteToolbox
using SymEngine
using DifferentialEquations
using Polynomials
fileF107 = open("C:/stj/Julia/f107.txt","r")
linesF107 = readlines(fileF107)
spk = SPK("C:/stj/Julia/de430.bsp")
jd = DatetoJD(2018,01,01,0,0,0) * 86400
jd2 = DatetoJD(2018,01,11,0,0,0) * 86400
sputnik_coord = [-976.3107644649057, -4835.627052558522, -5031.728586125443, -0.7944031487816871, 5.474532271429767, -5.094496750907486]
Kps = [2,1,1,1,2,1,0,4,2,0]
h0 = 90
hx = 125
T0 = 183
M0 = 28.96
rho0 = 3.46e-12
g = 9.8065
Ra = 6356766
R = 8.31432
req = BigFloat(6378136.3)
sun_declination_degree = [ -22.94980416,
-22.8593264,
-22.76126935,
-22.65568101,
-22.54261303,
-22.42212068,
-22.29426272,
-22.15910134,
-22.01670204,
-21.86713355
]
c = [0.0,0.0,0.0,0.0,0.0]
c[1] = -89284375.0
c[2] = 3542400.0
c[3] = -52687.5
c[4] = 340.5
c[5] = -0.8
cstar = c
A = [0.0,0.0,0.0,0.0,0.0,0.0,0.0]
A[1] = 83809.05064
A[2] = -5196.932946
A[3] = 134.0855452
A[4] = -1.842006056
A[5] = 1.421149e-2
A[6] = -5.83912e-5
A[7] = 9.9826e-8
alpha = [
3144902516.672729,
-123774885.4832917,
1816141.096520398,
-11403.31079489267,
24.36498612105595,
0.008957502869707995
]
beta = [
52864482.17910969,
16632.50847336828,
-1.308252378125,
0.0,
0.0,
0.0
]
B = [0.0,0.0,0.0,0.0,0.0,0.0]
function getF107(daynum)
stringF107 = split(linesF107[40 + daynum])
F107 = parse(stringF107[4])
return F107
end
function getF107a(daynum)
sum = 0
for day = (0:80)
stringF107 = split(linesF107[daynum + day])
F107 = parse(stringF107[4])
sum = sum + F107
end
sum = sum / 81
return sum
end
function getHeight(y)
a = sqrt(y[1]^2 + y[2]^2 + y[3]^2)-Ra/1000
return a
end
function temperature(h, date)
date = jd2/86400
if h < 125
daynum = trunc(Int64,jd2/86400 - jd/86400)
F107 = getF107(daynum)
F107a = getF107a(daynum)
Tc = 379 + 3.24*F107a + 1.3*(F107 - F107a)
st_bar_sun = state(spk, 0, 10, date)
st_bar_moon_earth = state(spk, 0, 3, date)
st_bar_me_earth = state(spk, 3, 399, date)
earth_solar_barycentre = st_bar_moon_earth + st_bar_me_earth
sun_coord = (st_bar_sun - earth_solar_barycentre)
global phi_gc = y[1]/sqrt(y[1]^2+y[2]^2)
global phi_gd = atan(tan(phi_gc)/(1 - (0.0167)^2))
global delta = sun_declination_degree[daynum]/57.2958
global eta = abs(phi_gd - delta)/2
global theta = abs(phi_gd + delta)/2
LHA = 180/pi*(
(y[1]*sun_coord[2] - y[2]*sun_coord[1])/(abs(y[1]*sun_coord[2] - y[2]*sun_coord[1]))*
acos((y[1]*sun_coord[2] + y[2]*sun_coord[1])/(sqrt(y[1]^2 + y[2]^2)*sqrt(sun_coord[1]^2 + sun_coord[2]^2))))
tau = LHA - 37 + 6*sin(LHA + 43)
Tunc = Tc*(1 + 0.3*(sin(theta)^2.2 + (cos(eta)^2.2 - sin(theta)^2.2)*cos(tau/2)^3))
end
Kp = Kps[daynum]
if (h >= 200)
deltaTcorr = 28*Kp + 0.03*exp(Kp)
else
deltaTcorr = 14*Kp + 0.02*exp(Kp)
end
global Tcorr = Tunc + deltaTcorr
global Tx = 371.6678 + 0.0518806*Tcorr - 294.3505*exp(-0.00216222*Tcorr)
deltaT = 0
for i = (1:5)
deltaT += c[i]*h^(i - 1)
end
global d1 = Tx - T0
if h < 125
T = Tx + (d1/35^4)*deltaT
end
return T
end
function molecular_mass(y,date)
h = 90
if h <= 100 && h >= 90
M = 0
for i = 1:7
M += A[i]*h^(i - 1)
println("i = $i, added $(A[i]*h^(i - 1))")
end
return M
end
end
y = sputnik_coord
date = jd2/86400
println(molecular_mass(y,date))
function density(y, date)
M = molecular_mass(y, date)
T = temperature(y, date)
k = -g/(R*(Tx-T0))
f = (35^4)*(Ra^2)/c[5]
cstar[1] = 35^4 * [1 +T0/(Tx- T0)] + c[1]
P = Poly([cstar[1],cstar[2],cstar[3],cstar[4],cstar[5]])
roots_of_P = [0.0,0.0,0.0,0.0]
roots_of_P = roots(P)
println(roots_of_P)
r1 = 0
r2 = 0
x = 0
y = 0
if imag(roots_of_P[1]) == 0
r1 = real(roots_of_P[1])
else
x = real(roots_of_P[1])
y = abs(imag(roots_of_P[1]))
end
if imag(roots_of_P[2]) == 0
if r1 != 0
r2 = real(roots_of_P[2])
else
r1 = real(roots_of_P[2])
end
else
x = real(roots_of_P[2])
y = abs(imag(roots_of_P[2]))
end
if imag(roots_of_P[3]) == 0 && r1 != 0
r2 = real(roots_of_P[3])
elseif imag(roots_of_P[3]) == 0 && r1 == 0
r1 = real(roots_of_P[3])
else
x = real(roots_of_P[3])
y = abs(imag(roots_of_P[3]))
end
if imag(roots_of_P[4]) == 0
r2 = real(roots_of_P[4])
end
B[1] = (A[1] - 5.04227040425412*cstar[1])*f
B[2] = (17856541.74708379 + 0.00158642630679*cstar[1])*f107
B[3] = (-259910.779829766 - A[7]*cstar[1]/c[5])*f
B[4] = -1.236944975267146e17
B[5] = 2.642300254604438e14
B[6] = 9.740305355778338e10
S1 = 0
S2 = 0
SRminus = 0
for i = (1:6)
S1 += B[i]*r1^(i-1)
S2 += B[i]*r2^(i-1)
SRminus += B[i]*(-Ra)^(i-1)
end
X = -2*rl*r2*Ra*(Ra^2 + 2*x*Ra + x^2 + y^2),
U1 = (r1 + Ra)^2 * (r1^2 - 2*x*r1 + x^2 + y^2)* (r1 - r2)
U2 = (r2 + Ra)^2 * (r2^2 - 2*x*r2 + x^2 + y^2)* (r1 - r2)
V = (Ra^2 + 2*x*Ra + x^2 + y^2)*(-Ra - r1)*(-Ra - r2)
W1 = r1*r2*(Ra^2)*(r1 + Ra) + (x^2 + y^2)*Ra*(Ra*r1 + r1r2)
W2 = r1*r2*(Ra^2)*(r2 + Ra) + (x^2 + y^2)*Ra*(Ra*r2 + r1r2)
p2 = S1/U1
p3 = -S2/U2
p5 = SRminus/V
p4 = (B[1] - r1*r2*Ra^2* (B[5] + (2*x + r1 + r2 - Ra) *B[6]) - r1*r2*Ra*(x^2 + y^2)*B[6] + r1*r2*(Ra^2 - (x + y))*p5 + W1*p2 +W2*p3)/X
F1 = ((h + Ra)/(h0 + Ra))^p1 *((h - r1)/(h0 - r1))^p2 * ((h - r2)/(h0 - r2))^p3 * ((h^2 - 2*x*h + x^2 +y^2)/(h0^2 - 2*x*h0 + x^2 + y^2))^p4
p6 = B[5] + (2*x + r1 + r2 - Ra)*B[6] - p5 - 2*(x + Ra)*p4 - (r2 + Ra)*p3 - (r1 + Ra)*p2
p1 = B[6] - 2*p4 - p3 -p2
F1 = ((h+Ra)/(h0+Ra))^p1 *((h-r1)/(h0-r1))^p2 *((h-r2)/(h0-r2))^p3 *(((h^2)-2*x*h + x^2 +y^2)/((h0^2)-2*x*h0 + x^2 +y^2))^p4
F2 = (h-h0)*(f*A[7] + p5/((h + Ra)*(h0 + Ra))) + p6/y *atan((y*(h-h0))/(y^2+(h-x)*(h0-x)))
rho = rho0*(F1^k)*exp(k*F2)*((M*T0)/(M0*T))
return rho
end
toc()
在注释density
函数之后,该错误消失了,因此该函数存在该错误。我发现这个issue遇到类似的问题,但无法解决问题。我在代码中寻找了-2,但在我看来,这并不是真正的原因。对我来说似乎唯一可疑并且(可能是)可能包含错误的部分是计算F1
的行。有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
在计算X
的部分出现了错误:
X = -2*rl*r2*Ra*(Ra^2 + 2*x*Ra + x^2 + y^2),
这里不需要逗号。