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

James Tursa
James Tursa 2020년 12월 21일
Your equation says -5 but you have coded -4.
Levente Gáti
Levente Gáti 2020년 12월 21일
Sorry for the misstyping

댓글을 달려면 로그인하십시오.

 채택된 답변

Sean de Wolski
Sean de Wolski 2020년 12월 21일

0 개 추천

-4 v -5?

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 12월 21일

0 개 추천

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
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 12월 21일

편집:

2020년 12월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by