从Maxima CAS中的函数值列表中找到函数的根

时间:2018-07-26 16:20:00

标签: list numerical-methods maxima equation-solving

在Maxima CAS中,我有一个列表(此处仅显示一些值)

pp:[2.224930361893751E-5,2.106533424809514E-5,1.987219192893519E-5,1.867039677797E-5,1.746047267164874E-5,1.624294701768613E-5,1.501835052467037E-5,1.378721697090773E-5,1.25500829711786E-5,1.130748774272327E-5,1.005997286991633E-5,8.808082068087475E-6,7.552360946350145E-6,6.293356769639102E-6,5.031618219769607E-6,3.767695156954576E-6,2.502138378962515E-6,1.23549938203793E-6,-3.166988037095475E-8,-1.298817237566085E-6,-2.565390542642876E-6,-3.83083791286043E-6,-5.094607970414222E-6,-6.3561500823206E-6,-7.614914600641287E-6,-8.870353101722573E-6,-1.012191862512224E-5,-1.136906591173853E-5,-1.261125164149501E-5,-1.384793466965156E-5,-1.507857626262959E-5,-1.63026403323524E-5,-1.751959366975281E-5,-1.872890617687916E-5,-1.993005109740542E-5,-2.112250524602399E-5,-2.230574923611089E-5,-2.34792677056006E-5,-2.464254954120948E-5,-2.579508810070241E-5]

一个函数的浮点值

y =  f(x)

列表是有序的:列表中的位置与x成正比。

从0到1,n点。

如果我绘制列表,则得到a diagram of my function

enter image description here

我可以find maximal value and it's index

dpMax : lmax(pp), 
iMax : sublist_indices(pp, lambda([p], p = lmax(pp))),

和根(x:f(x)= 0)

ppa : map(abs, pp),
dpMin : lmin(ppa), 
iMin : sublist_indices(ppa, lambda([p], p = lmin(ppa))),

但是它只能找到一个根。可以看到这里有2个根吗?

如何找到第二个根?

也许:

  • 找到标志变化的点

====编辑===

这是finding gradient of the 2D scalar field

的一部分

1 个答案:

答案 0 :(得分:1)

我可以通过检查值的符号来做到这一点:

GiveRoots(List):=block(
    [i,  rr],
    rr:[],
    for i:1 thru length(List)-1 step 1 do 
        if (is (sign(List[i]) # sign(List[i+1])))
             then rr: endcons([i, List[i]],rr),
    rr  
)$

现在:

enter image description here

相关问题