- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现 deflation method用于在 Julia 上找到多项式的多个根。在紧缩方法中,新函数是由实际函数除以x - x_roots[i]
生成的。 ,并且必须找到新生成的函数的根。但是g(x) = g(x) / (x - x_root)
给了我一个堆栈溢出错误,因为它可能产生了无限递归关系。如何在每个步骤中生成一个新函数?
function deflation(f::Function, order)
roots=[]
n=1
g(x)=f(x)
x_root=Muller_method(f,-5,0,5,1e-5,50)
while n<=order
x_root=Muller_method(a,-5,0,5,1e-5,50)
g(x)=g(x)/(x-x_root)
append!(roots,x_root)
n=n+1
end
return (roots)
最佳答案
这样的事情会导致无限递归:
julia> g(x) = x
g (generic function with 1 method)
julia> g(1)
1
julia> g(x) = g(x) / 2
g (generic function with 1 method)
julia> g(1)
ERROR: StackOverflowError:
Stacktrace:
[1] g(::Int64) at ./REPL[3]:1 (repeats 79984 times)
这是因为函数(或方法)定义不像变量赋值那样工作:每次重新定义
g(x)
覆盖前一个(注意上面的
g
如何只有一种方法)。当一个方法定义引用它自己时,它是递归的,即它在调用函数时引用它自己的版本。
julia> f(x) = (x-1) * (x-2)
f (generic function with 1 method)
julia> roots = Float64[]
Float64[]
# g is defined once, and accounts for all currently found roots
julia> g(x) = f(x) / reduce(*, x-root for root in roots; init=one(x))
g (generic function with 1 method)
# No roots are identified at the beginning
julia> g(1+eps())
-2.2204460492503126e-16
julia> g(2+eps())
0.0
# But the results produced by g update as roots are identified
julia> push!(roots, 1.)
1-element Array{Float64,1}:
1.0
julia> g(1+eps())
-0.9999999999999998
julia> g(2+eps())
0.0
关于julia - 多根查找的放气方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63888581/
我在启动时为我的 mac 应用程序进行时间分析,我不记得在雪豹中看到过这个类,但不能确定。有谁知道它是做什么用的? 最佳答案 这是 Lions 的新功能,用于保存和恢复窗口状态(如位置等)。它通过压缩
我有一些想法想要尝试与数据压缩相关,但我发现很难破译该标准在“现实生活中”如何应用的某些部分。我想查看一些示例压缩文件,以观察 block 的排列方式以及哈夫曼树的结构。 是否有任何工具可以帮助可视化
这个问题已经有答案了: python: read lines from compressed text files (4 个回答) 已关闭 8 年前。 我使用以下生成器以内存高效的方式逐行迭代给定的
我正在向 cloudfront CDN 发出请求并看到非常令人沮丧的行为。在 chrome 和 firefox 中,请求传递了正确的 accept-encoding:gzip, deflate hea
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
总结:我需要一个 PNG 编写器,出于各种原因我不得不从头开始。我不需要压缩图像数据,所以我使用无压缩 deflate 算法实现了 PNG。需要多个压缩 block 的图像渲染失败,似乎是因为它忽略了
是否有隐藏在 Internet 中的 ByteBuffers 方面的 gzip-deflating 库?允许我们推送原始数据然后提取缩减数据的东西?我们搜索了它,但只找到处理 InputStreams
我正在使用 zlib压缩文本数据流。文本数据以 block 的形式出现,对于每个 block ,deflate()被调用,flush 设置为 Z_NO_FLUSH .检索到所有 block 后,def
我已在网站的 .htaccess 文件中指定了以下属性: AddOutputFilterByType DEFLATE image/svg+xml DeflateCompressionLevel 9 H
我是一名优秀的程序员,十分优秀!