【发布时间】:2014-09-18 01:50:53
【问题描述】:
我有矢量x = 1:1:100
我的函数sin_N(x, iterations) 使用求和技术逼近sin(x),其中迭代作为要计算总和的项数。 sin_N 返回一个作为求和结果的数字。
我想将值 x 传递给 sin_N 以便得到一个 x 长度向量,其中每个元素都是求和的下一步。
我认为它看起来像这样(在这种情况下,我近似于 sin(2)):
y2 = sin_N(2, x)
但是 y2 最终只是 2。
谁能告诉我我做错了什么?
function [sinApprox] = sin_N(sinVal, iters)
newN = sinVal
sinApprox = sinVal
for a=2:iters
newN = (-1).^(a-1).* abs(newN) .* ((sinVal .^ 2)/((2.*a - 1).*(2.*a-2)))
sinApprox = sinApprox + newN
end
【问题讨论】: