Is this right?

3 Ansichten (letzte 30 Tage)
Levente Gáti
Levente Gáti am 21 Dez. 2020
Bearbeitet: James Tursa am 21 Dez. 2020
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 Kommentare
James Tursa
James Tursa am 21 Dez. 2020
Your equation says -5 but you have coded -4.
Levente Gáti
Levente Gáti am 21 Dez. 2020
Sorry for the misstyping

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 21 Dez. 2020
-4 v -5?

Weitere Antworten (1)

Image Analyst
Image Analyst am 21 Dez. 2020
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 Kommentar
James Tursa
James Tursa am 21 Dez. 2020
Bearbeitet: James Tursa am 21 Dez. 2020
"... 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by