在 Julia 中使用迭代和 println 挣扎
Struggling with using iteration and println in Julia
我是 Julia 的新手,正在尝试了解其工作原理。
下面是我刚刚写的示例代码。
(这是基线代码,我打算一一添加其他行。)
我希望看到类似 1 2 3 4 5 6 7... 来自 test = check(m)
但是,我没有看到任何结果。
非常感谢任何帮助。
using Pkg
using Optim
using Printf
using LinearAlgebra, Statistics
using BenchmarkTools, Optim, Parameters, QuantEcon, Random
using Optim: converged, maximum, maximizer, minimizer, iterations
using Interpolations
using Distributions
using SparseArrays
using Roots
# ================ 1. Parameters and Constants ============================
mutable struct Model
# Model Parameters and utility function
δ::Float64
function Model(;
δ = 0.018,
)
new(
δ
)
end
end
function check(m)
it = 0
tol=1e-8
itmax = 1000
dif = 0
# Iteration
while it < itmax && dif >=tol
it = it + 1;
V = Vnew;
println(it)
end
return itmax
end
m=Model()
test = check(m)
dif = 0
tol = 1e-8
while it < itmax && dif >= tol
现在向我解释如何
>=直到
我是 Julia 的新手,正在尝试了解其工作原理。
下面是我刚刚写的示例代码。
(这是基线代码,我打算一一添加其他行。)
我希望看到类似 1 2 3 4 5 6 7... 来自 test = check(m)
但是,我没有看到任何结果。
非常感谢任何帮助。
using Pkg
using Optim
using Printf
using LinearAlgebra, Statistics
using BenchmarkTools, Optim, Parameters, QuantEcon, Random
using Optim: converged, maximum, maximizer, minimizer, iterations
using Interpolations
using Distributions
using SparseArrays
using Roots
# ================ 1. Parameters and Constants ============================
mutable struct Model
# Model Parameters and utility function
δ::Float64
function Model(;
δ = 0.018,
)
new(
δ
)
end
end
function check(m)
it = 0
tol=1e-8
itmax = 1000
dif = 0
# Iteration
while it < itmax && dif >=tol
it = it + 1;
V = Vnew;
println(it)
end
return itmax
end
m=Model()
test = check(m)
dif = 0
tol = 1e-8
while it < itmax && dif >= tol
现在向我解释如何 >=直到