作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
function lg(X,Y,Xint)
n = length(X)
L = ones(1:n)
for k = collect(1:n)
L[k] = 1
for c = collect(1:n)
if c!=k
L[k] = (L[k]*( Xint - X[c] ))/( X[k] - X[c] )
end
end
end
return sum(Y.*L)
end
==========================
执行时
加载错误:不精确错误()加载 In[76] 时,在第 1 行开始的表达式中
在 In[74]:11 处的 lg 中?
最佳答案
ones
范围创建一个 Int64 数组:
julia> o = ones(1:3)
3-element Array{Int64,1}:
1
1
1
julia> o[1] = 3.5
ERROR: InexactError()
in setindex!(::Array{Int64,1}, ::Float64, ::Int64) at ./array.jl:339
in eval(::Module, ::Any) at ./boot.jl:226
您无法将 Float64 分配给 Int64 数组(您会收到此错误)。
您只想使用 ones(n)
来获取 Float64 数组:
julia> ones(3)
3-element Array{Float64,1}:
1.0
1.0
1.0
<小时/>
旁注:在迭代某个范围之前,您不需要收集
:
for k = collect(1:n)
只需迭代范围即可:
for k = 1:n
关于function - Julia :怎么了!拉格朗日多项式函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37494160/
我是一名优秀的程序员,十分优秀!