I have this code with the following instructions (I'm doing numerical integration and was trying to see how to do it all)
--[[
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
My question is -- when running the actual programme, here I'm running it in overleaf, as it has to be presented as a report - how do I edit the code that I wrote to ensure that the code allows me to present the table too?
As additional information - init_trapezoidal computes the 1 sub interval and half_trapezoidal computes it for n_subint intervals
Thank you for your help