提问人:CrSb0001 提问时间:10/3/2023 更新时间:10/3/2023 访问量:31
这是计算 Scratch 中积分从一个点到第二个点的面积的可靠方法吗?
Would this be a reliable way of calculating the area from a point to a second point of an integral in Scratch?
问:
因此,为了好玩,我做了一个编码练习(在 Scratch 中),并决定尝试创建一段代码,该代码能够计算 ∫ab f(x) dx 形式的函数 f(x)=x y(其中 y 是某个常数)的面积,我认为我可能能够做到。
我对此所做的尝试始于知道我有有助于解决这个问题的代码:
[scratchblocks]
define pow(base)(power)
set [result v] to [1]
set [base v] to (base)
set [power v] to (round (power))
set [done v] to [0]
if <(power) < [0]> then
set [base v] to [((1) / (base))]
set [power v] to [-1(() *(round (power))]
end
repeat until <[done v] = [1]>
if <(([power v]) mod (2)) = [0]> then
set [result v] to (([result v]) * ([base v]))
change [power v] by (-1)
end
if <(([power v]) mod (2)) > [0]> then
set [done v] to [1]
end
if <<not <<[done v] = [1]>>>
set [base v] to (([base v]) * ([base v]))
set [power v] to (([power v]) / (2))
end
end
[/scratchblocks]
我还必须创建一些新代码来实际计算积分,但这并不难:
[scratchblocks]
define area from x to y of the form a^zda(x)(y)(z)
set [x v] to (x)
set [y v] to (y)
set [z v] to (z)
pow (x) ((z)+(1))
set [re2 v] to (result)
pow (y) ((z)+(1))
set [re3 v] to (result)
set [re4 v] to (((re3)-(re2))/(3))
[/scratchblocks]
现在,为了测试,我做了 ∫34 a 2da,这应该得到我们 (4^3)/3-9=64/3-9=21+(1/3)-9=12+(1/3)≈12.333
它似乎已经做到了。
我的问题
这是计算 ∫a b x^adx Scratch 形式的积分的一个点到第二个点的面积的可靠方法,还是我能做些什么来使其更可靠地做到这一点?
答: 暂无答案
评论