fzero of vector with a loop
Afficher commentaires plus anciens
I'm trying to find the s vector that will gave me the value of ValorMercado=ValorMercadonovo.
This is my code:
Price=[99.23;100.05;91;107.71;104.1];
cashflows=[3441 3441 301720.5;68750 1068750 0;170040 13085020 0;229350 229350 5729350;34194000 0 0];
NominalValue=[300000;1000000;13000000;5500000;32800000];
eiopa=[-0.00302;-0.00261;-0.00208];
[c3,r3]=size(Price);
[c4,r4]=size(cashflows);
ValorMercado(1:c3,1)=Price(1:c3,1).* NominalValue(1:c3,1) ./100;
s=transpose(sym ('s',[1 c3]));
S=sym(zeros(c3,1));
for i=1:c3
ValorMercadonovo(i,1)(S)=0;
for j=1:r4
ValorMercadonovo(i,1)(S)=(ValorMercadonovo(i,1)/((1+eiopa(j,1)+S(i,1))^j))+(cashflows(i,j)/((1+eiopa(j,1)+S(i,1))^j));
end
end
for i=1:c3
x(i,1)=fzero(@(S)ValorMercado(i,1) - ValorMercadonovo(S)(i,1),[0,1]);
end
the error is Error: ()-indexing must appear last in an index expression.. What is wrong?
1 commentaire
Alan Weiss
le 14 Juil 2017
Please correct the error in your displayed code so that we can see what the issue might be. As Matt J said, the current question has an obvious syntax error, and we cannot proceed.
Alan Weiss
MATLAB mathematical toolbox documentation
Réponses (1)
Matt J
le 14 Juil 2017
The expression
ValorMercado(S)(i,1)
doesn't make sense. ValorMercado is a numeric vector, so can only be indexed with one pair of ()
2 commentaires
Mariana Ferreira
le 14 Juil 2017
Matt J
le 14 Juil 2017
No, we need to know what the new error messages are. Also, I still see
ValorMercadonovo(i,1)(S)
What is it supposed to mean?
Catégories
En savoir plus sur Optimization Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!