How can I make fsolve work with vector outputs?
Mostrar comentarios más antiguos
Hi! currently writing Merton's credit risk model. I want to input Vectors with loads of data points however I am trialling it with simple vectors of 3 numbers, therefore looking for a vector that will have 6 outputs. (Each simulation has 2 answers therefore looking to get a 2x6 output)
At the moment getting this error code: Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
function VolAssetsVec = VolatilityAssetsVec(y)
A = y(:,1);
sigmaA = y(:,2);
S = [100,150,200];
sigmaS = [0.3, 0.25, 0.2];
r = [0.03,0.25, 0.2];
F = [60, 60,60];
tau = 1;
x = (log(A./F)+(r+sigmaA.^2./2).*tau./(sigmaA.*sqrt(tau)));
VolAssetsVec(:,1) = S-A.*normcdf(x)+F.*exp(-r.*tau).*...
normcdf(x-sigmaA.*sqrt(tau));
VolAssetsVec(:,2) = sigmaA-sigmaS.*S./(A.*normcdf(x));
end
Solving it using the following
y0 = [c,d];
options = optimset('display','iter');
[y] = fsolve(@VolatilityAssetsVec, y0,options);
Any help would be much appreciated!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!