how to keep adding a varaible in a loop?

1 次查看(过去 30 天)
i have this code which i want to write in a loop because it has to go on for a 1000 or so and i dont know how to make a loop for this inverval
NASDAQ_low = [norminv(1-NASDAQ(1,1)) norminv(1-(AA(1,1)+AA(1,2))) norminv(1-(AA(1,1)+AA(1,2)+ AA(1,3))) norminv(1-(AA(1,1)+AA(1,2)+AA(1,3)+AA(1,4))) norminv(1-(AA(1,1)+AA(1,2)+AA(1,3)+AA(1,4)+AA(1,5)) .... and so on
i also want to do the same for this
exp^LIBOR *(1+X)/(1-X)^2 + exp^LIBOR *(1+X)/(1-X)^2 + (1+X)/(1-X)^3 + exp^LIBOR *(1+X)/(1-X)^2 + (1+X)/(1-X)^3+ (1+X)/(1-X)^4 + exp^LIBOR *(1+X)/(1-X)^2 + (1+X)/(1-X)^3+ (1+X)/(1-X)^4
(1+X)/(1-X)^5 + etc....
could anyone give me a clue?
thank you in advance

回答(1 个)

Sara Boznik
Sara Boznik 2021-4-5
First one:
n=1;
suma=0
for n=1:1:1000
AA(1,n)
suma=AA(1,n)+suma;
norminv=1-suma
n=n+1;
end
Second one:
k=2;
suma=0;
for k=2:1:1000;
part=exp^LIBOR *(1+X)/(1-X)^k;
suma=suma+part;
k=k+1
end

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by