How can I make fsolve work with vector outputs?

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!

 채택된 답변

Walter Roberson
Walter Roberson 2018년 7월 28일
편집: Walter Roberson 2018년 7월 28일

0 개 추천

fsolve() will never return multiple solutions. If you want two solutions, you need to run fsolve() twice with different starting points that hopefully lead to different solutions.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2018년 7월 28일

댓글:

2018년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by