fzero of vector with a loop

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 个评论

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

请先登录,再进行评论。

回答(1 个)

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 个评论

It was there by lapse. Already fixed but its not working anyway. Could you help please?
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?

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by