【问题标题】:Is there a recursive, iterative way to determine a value with a given condition?是否有一种递归、迭代的方式来确定具有给定条件的值?
【发布时间】:2022-01-22 01:40:41
【问题描述】:

我写了一个程序来计算流体静力太阳大气的等离子体β:

B_0 = 0.02 # base magnetic field [T]
p_0 = 0.015 # base pressure [J/m^-3]
h_D = 7.5E7 # dipole depth [m]
R_☉ = 6.96E8 # solar radius [m]
M_☉ = 1.9891E30 # solar mass [kg]
G = 6.673E-11 # gravitational constant [m^3 kg^-1 s^-2]
μ = 0.61 # mean molecular weight of solar corona
m_H = 1.6726E-27 # mass of H particle [kg]
μ_0 = (4*pi)*10^(-7) # permeability [H/m]
k = 1.3806E-23 # boltzmann constant [J/K]
T = 1E6 # temperature [K]

g = (G*M_☉)/(R_☉^2)

lambda_p = (k*T)/(μ*m_H*g)    # coronal scale height for 1MK [m]

p(h) = p_0*exp(-h/lambda_p)
B(h) = B_0*(1 + (h/h_D))^(-3)

beta = p(h)/(B(h)^2 / (2*μ_0) )

我对使用迭代/数值方法不是很熟悉,想知道是否有办法在beta = 1 时确定h 的值?

【问题讨论】:

    标签: julia


    【解决方案1】:

    你可以使用Roots.jl

    using Roots
    function beta(h)
      return p(h)/(B(h)^2 / (2*μ_0) )
    end
    
    f0 = h-> beta(h) - 1
    Roots.find_zero(f0,2*h_D) # -2.3540849742856756e8
    

    【讨论】:

    • 2*h_D 在这里是什么意思?结果不应该是负面的。
    • 我用它作为根查找器的初始点(乍一看,h_D 似乎与h 的大小相同)。结果很奇怪,但它来自评估贴出代码。从任何位置开始似乎都会收敛到该值。公式对吗?
    • 用这个公式,我们可以检查一些点:h = lambda_p = 5e7:beta = 0.0007431374419951913 h = h_D = 7.5E7 :beta = 0.001345889418079913 当h趋于无穷大时,@98765432@趋于零。贝塔(0)= 9.424777960769383e-5。
    • 我刚刚更新了帖子中的常量,所以也许复制并粘贴到您的代码中并再次检查?
    猜你喜欢
    • 2021-01-05
    • 2013-01-12
    • 2013-11-08
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多