Subscripted assignment dimension mismatch

1 visualización (últimos 30 días)
Catarina
Catarina el 17 de Dic. de 2014
Comentada: Guillaume el 17 de Dic. de 2014
Hello! I have the following problem: Matlab tells me there is a "subscripted assignment dimension mismatch". This the code I'm trying to run:
N = 1:20;
extrapolatedmaturities = 1:100;
Price = zeros(s,length(extrapolatedmaturities));
for t = 1:s
for i = 1:length(extrapolatedmaturities)
Price(t,:) = exp(-UFR*i)+...
(z(:,t)'*SWfunction(N,maturities2,alpha,UFR));
end
end
Where UFR is a number, z is a N by t matrix (which I invert) and SWfunction produces a N by N matrix. What I want matlab to do is to produce a t by i matrix where for all columns it computes exp(-UFR*i) and up to N add it to the second term, in which it should take for each t the row of values in z, multiply it by the NxN matrix from the SWfunction. Can someone help me? I've tried so many ways of doing this and it always tells me there is a dimension mismatch...

Respuesta aceptada

Thorsten
Thorsten el 17 de Dic. de 2014
The term exp(-UFR*i) is indepent of t, so you could compute it as
for i = 1:length(extrapolatedmaturities)
expUFR(i) = exp(-UFR*i);
end
And then use
for t = 1:s
Price(t,:) = expUFR + z(:,t)'*SWfunction(N,maturities2,alpha,UFR);
end
  3 comentarios
Guillaume
Guillaume el 17 de Dic. de 2014
Editada: Guillaume el 17 de Dic. de 2014
Actually, for even speedier calculation, you can calculate expUFR without a loop:
expUFR = exp(-UFR*(1:length(extrapolatedmaturaties)));
or even
expUFR = exp(-UFR*extrapolatedmaturaties); %since extraxxx is 1:100
Guillaume
Guillaume el 17 de Dic. de 2014
And also, unless SWfunction output can change for the same input that can also be calculated once out of the loop, since it doesn't depend on t either:
expUFR = exp(-UFR*extrapolatedmaturaties)
SWvalue = SWfunction(N, maturities2, alpha, UFR);
for t = 1:s
Price(t, :) = expUFR + z(:, t)' * SWvalue;
end
And I'm sure even the t loop could be vectorised although I can't think how right now.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by