Function 如何计算lua中的表
我有以下指令的代码(我正在做数值积分,并试图看看如何做这一切) 我的问题是——当运行实际的程序时,我在背面运行它,因为它必须以报告的形式呈现——我如何编辑我编写的代码以确保代码允许我也呈现表 作为附加信息-init_梯形计算1个子区间 半梯形计算n次整数区间Function 如何计算lua中的表,function,loops,lua,integration,Function,Loops,Lua,Integration,我有以下指令的代码(我正在做数值积分,并试图看看如何做这一切) 我的问题是——当运行实际的程序时,我在背面运行它,因为它必须以报告的形式呈现——我如何编辑我编写的代码以确保代码允许我也呈现表 作为附加信息-init_梯形计算1个子区间 半梯形计算n次整数区间 感谢您的帮助您能提供一个示例输入、当前输出和所需输出吗?我想您要问的是,如何转储表中的内容。有几种方法--通常称为prettyprint或serialize--如果您不告诉我们应该是什么样子,我们就无法告诉您如何输出某些内容。可能您需要类似
感谢您的帮助您能提供一个示例输入、当前输出和所需输出吗?我想您要问的是,如何转储表中的内容。有几种方法--通常称为prettyprint或serialize--如果您不告诉我们应该是什么样子,我们就无法告诉您如何输出某些内容。可能您需要类似dumptable:的内容或将数据输出为JSON:
--[[
Calculates a table of successive trapezoidal estimates
for the integral of f from a to b. It creates a table
"estimates" such that
estimates[1] is the trapezoidal estimate for one sub interval
estimates[2] is the trapezoidal estimate for two sub intervals
estimates[3] is the trapezoidal estimate for four sub intervals
estimates[4] is the trapezoidal estimate for eight sub intervals
and so on to
estimates[n+1] is the trapezoidal estimate for 2^n sub intervals
where n is the value of max_n_doublings (25 by default)
In all cases, sub intervals have equal width.
It does this by calling the init_trapezoidal and half_trapezoidal
functions and combining this with the previous estimate.
The function returns the table estimates.
--]]
function compute_trapezoidal_table(f,a,b,max_n_doublings)
max_n_doublings = max_n_doublings or 25
estimates = {}
estimates[1] = init_trapezoidal(f,a,b)
for i = 2, max_n_doublings do
local intervals = 1
estimates[i] = half_trapezoidal(f,a,b,intervals)
intervals = intervals * 2
end
print(table.concat(estimates," "))
end