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.

1 件のコメント

Brandon Troak
Brandon Troak 2018 年 7 月 29 日
Is there no way of putting it through a loop?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by