Is this right?
2 次查看(过去 30 天)
显示 更早的评论
Okay so my task is:
I have to make a script in matlab, which gives back the product of the first 10 element.(of this equation)
fn=((n^2)+n)/((n^3)+n!-4)
Is this right?
y=1
for i=1:10
y=y*(((i*i)+i)/((i*i*i)+(factorial(i))-4))
end
Thanks for helping, it means a lot.
2 个评论
采纳的回答
更多回答(1 个)
Image Analyst
2020-12-21
I think you need to subtract 5 instead of 4, and I think your for loop needs to start at 2 since you already computed the first term with y=1. Compare your results with the vectorized version:
n = 1 : 10;
fn = ((n.^2)+n) ./ ((n.^3) + factorial(n) - 5)
result = prod(fn)
1 个评论
James Tursa
2020-12-21
编辑:James Tursa
2020-12-21
"... I think your for loop needs to start at 2 ..."
The loop indexing needs to start at 1 as written unless you know that the first term is 1 exactly.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!